#include<stdio.h>
#include<malloc.h>
#define Elem int
typedef struct sqlist{
Elem key ;
int data ;
}sqlist ;
void quicksort(sqlist R[] , int min , int max){
int i ,j ;
i = min ;
j = max ;
sqlist temp ;
if(min<max){
temp = R[i] ;
while(i != j){
while(i<j && temp.key < R[j].key){
j-- ;
}
if(i<j){
R[i] = R[j] ;
} www.2cto.com
while(i<j && temp.key > R[i].key){
i++ ;
}
if(i<j){
R[j] = R[i] ;
}
}
R[i] = temp ;
quicksort(R , min , i-1) ;
quicksort(R , i+1 , max) ;
}
}
void main(){
sqlist dataSort[10] ;
int i = 0 ;
for(i = 0 ; i < 10 ; i++){
dataSort[i].key = 10 - i ;
dataSort[i].data = i ;
}
quicksort(dataSort , 0 , 9) ;
for(i = 0 ; i < 10 ; i++){
printf("key:%d data:%d \n",dataSort[i].key,dataSort[i].data) ;
}
}
w397090770的專欄