快速排序QuickSort.c
2010-05-21 20:13
295 查看
#include<stdio.h>
int sorted(int a[],int low,int high){
int temp=0;
int sign=a[low];
while(low<high){
while(low<high && sign<a[high])
--high;
temp=a[high];
a[high]=a[low];
a[low]=temp;
while(low<high && a[low]<sign)
++low;
temp=a[low];
a[low]=a[high];
a[high]=temp;
}
return low;
}
void sort(int a[],int low,int high){
int sign=0;
if(low<high){
sign=sorted(a,low,high);
sort(a,low,sign-1);
sort(a,sign+1,high);
}
}
void main()
{
int a[20];
int i=0;
int count=0;
printf("count= ");
scanf("%d",&count);
for(i=0;i<count;i++){
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
sort(a,0,count-1);
printf("/nThe sorted numbers:/n");
for(i=0;i<count;i++)
printf("%d ",a[i]);
printf("/nSort Work Is OK!/n/n");
getchar();
}
int sorted(int a[],int low,int high){
int temp=0;
int sign=a[low];
while(low<high){
while(low<high && sign<a[high])
--high;
temp=a[high];
a[high]=a[low];
a[low]=temp;
while(low<high && a[low]<sign)
++low;
temp=a[low];
a[low]=a[high];
a[high]=temp;
}
return low;
}
void sort(int a[],int low,int high){
int sign=0;
if(low<high){
sign=sorted(a,low,high);
sort(a,low,sign-1);
sort(a,sign+1,high);
}
}
void main()
{
int a[20];
int i=0;
int count=0;
printf("count= ");
scanf("%d",&count);
for(i=0;i<count;i++){
printf("a[%d]=",i);
scanf("%d",&a[i]);
}
sort(a,0,count-1);
printf("/nThe sorted numbers:/n");
for(i=0;i<count;i++)
printf("%d ",a[i]);
printf("/nSort Work Is OK!/n/n");
getchar();
}
相关文章推荐
- 快速排序:Quicksort(2)
- 快速排序——QuickSort——Python
- 快速排序QuickSort
- 第七章快速排序之“快速排序的随机化版本RANDOM-QUICKSORT”
- 快速排序(QuickSort)
- 【数据结构】快速(QuickSort)排序之——前后指针法
- 快速排序(QuickSort)
- QuickSort 快速排序
- QuickSort 快速排序
- 快速排序在Top k问题中的运用(quickSort and quickSelect in Top k)
- QuickSort快速排序
- Python--递归和快速排序 -- quickSort
- 算法导论 - QuickSort 快速排序 C++实现
- DualPivotQuickSort 双轴快速排序 源码
- 快速排序-Quicksort
- 算法导论学习--快速排序--Quicksort
- 快速排序(Quicksort)的Javascript实现
- quickSort - 快速排序
- 快速排序 QuickSort
- 快速排序_QUICKSORT