Pagini recente » Cod sursa (job #892311) | Cod sursa (job #300459) | Cod sursa (job #2122627) | Cod sursa (job #2115096) | Cod sursa (job #1779264)
#include <stdio.h>
#include <ctype.h>
#define BUF_SIZE 131072
int pos=BUF_SIZE,pos2,v[500000];
char buf[BUF_SIZE],buf2[BUF_SIZE];
FILE *fin,*fout;
inline char getch()
{
if(pos==BUF_SIZE)
fread(buf,BUF_SIZE,1,fin),pos=0;
return buf[pos++];
}
inline int read()
{
int x=0;
char ch=getch();
while(!isdigit(ch))
ch=getch();
do
{
x=x*10+ch-'0';
ch=getch();
} while(isdigit(ch));
return x;
}
inline void putch(char ch)
{
buf2[pos2++]=ch;
if(pos2==BUF_SIZE)
fwrite(buf2,BUF_SIZE,1,fout),pos2=0;
}
inline void write(int x)
{
char s[10];
int k=0;
do
{
s[k++]=x%10+'0';
x/=10;
} while(x);
while(k--)
putch(s[k]);
}
void myqsort(int start,int stop)
{
int i,j,pivot,aux;
i=start;j=stop;pivot=v[(i+j)/2];
while(i<=j)
{
while(v[i]<pivot)
i++;
while(v[j]>pivot)
j--;
if(i<=j)
{
aux=v[i];
v[i]=v[j];
v[j]=aux;
i++;j--;
}
}
if(j>start)
myqsort(start,j);
if(i<stop)
myqsort(i,stop);
}
int main()
{
fin=fopen("algsort.in","r");
fout=fopen("algsort.out","w");
int n,i;
n=read();
for(i=0;i<n;i++)
v[i]=read();
myqsort(0,n-1);
for(i=0;i<n;i++)
{
write(v[i]);
putch(' ');
}
if(pos2)
fwrite(buf2,pos2,1,fout);
fclose(fin);
fclose(fout);
return 0;
}