Kod: Zaznacz cały
#include <stdio.h>
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void sort(int l, int p)
{
int piwot=p-(p-l)/2;
int i,j;
swap(&tab[piwot],&tab[p]);
for(j=i=0;i<p;i=i+1)
{
if(tab[i]<piwot)
{
swap(&tab[i],&tab[j]);
j=j+1;
}
}
swap(&tab[j],&tab[p]);
if(l<j-1)
sort(l,j-1);
if(j+1<p)
sort(j+1,p);
}
int main()
{
int tab[10]={9,8,7,6,5,4,3,2,1,-1};
sort(tab[0],tab[9]);
for(int a=0;a<10;a=a+1)
{
if(a==0)
printf("
");
printf("%d ",tab[a]);
}
return 0;
}