#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define MAX_NUMBER 10
int partition(int data[], int low, int high)
{
int key = data[low];
int tmp;
while(low < high)
{
while(low < high && data[high] > key)
high--;
data[low] = data[high];
while(low < high && data[low] <= key)
low++;
data[high] = data[low];
}
data[low] = key;
return low;
}
void quick_sort(int data[], int low, int high)
{
int p ;
if(low < high)
{
p = partition(data,low,high);
quick_sort(data, 0, p-1);
quick_sort(data, p + 1, high);
}
}
int main()
{
int i;
int random[MAX_NUMBER];
for(i=0;i< MAX_NUMBER; i++)
{
//srand(time(NULL));
random[i] = rand() % MAX_NUMBER;
printf("num[%d] = %d
",i,random[i]);
}
quick_sort(random,0,MAX_NUMBER-1);
for(i=0;i< MAX_NUMBER;i++)
{
printf("%d
",random[i]);
}
return 0;
}