/* 二叉排序树
#include<stdio.h>
typedef struct binode
{
int data;
struct binode * lc , *rc;
}binode,*bitree;
int searchBST(bitree T, int x ,bitree p )
{
if(T==NULL)
return 0;
if(x==T->data) {p=T; return 1;}
else if(x>T->data) searchBST(T->rc,x,p);
else if(x<T->data) searchBST(T->rc,x,p);
}
*/
/*快速排序*/
#include<stdio.h>
#ifdef M
int partition(int data[],int left, int right)
{
int low , int high ;
int temp;
temp=data[low];
while(low<high)
{
while(low<high && data[high]>=temp) high--;
if(low < high ) {s[low]=s[high] ; }
while(low<high && data[low]<=temp) low++;
if(low<high) {s[high]=s[low];}
}
s[low]=temp;
return low;
}
void quicksort(int data[], int low ,int high)
{
int key;
if(low<high)
{
key=partition(data,low, high);
quicksort(data,low , key-1);
quicksort(data,key-1,high);
}
}
#else
void qsort(int data[], int left , int right)
{
int low , high , key ;
if(left < right)
{
low=left; high=right;
key=data[low];
if(low<high)
{
while(low<high && data[high]>=key) high--;
if(low<high) {data[low]=data[high];}
while(low<high && data[low <=key]) low++;
if(low<high) {data[high]=data[low];}
}
data[low]=key;
qsort(data, left,low-1);
qsort(data, low+1 ,right);
}
}
#endif
void main()
{
int i;
int data[10]= {0,1,2,5,4,7,8,9,6,3};
qsort(data,0 ,9);
;
for(i=0;i<10;i++){ printf("%d",data[i]); }
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布