📄 +
字号:
//快速排序
//本程序很简单,算法程序十分易懂,只需注意输入若干整数,以空格相隔,最后输入一个0结束
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
typedef struct data{
int key;
}data;
typedef struct{
data r[MAXSIZE+1];
int length;
}SqList;
int Partition(SqList&L,int low,int high){
int pivotkey;
L.r[0]=L.r[low];
pivotkey=L.r[low].key;
while(low<high){
while(low<high&&L.r[high].key>=pivotkey)high--;
L.r[low]=L.r[high];
while(low<high&&L.r[low].key<=pivotkey)low++;
L.r[high]=L.r[low];
}
L.r[low]=L.r[0];
return low;
}
void QSort(SqList&L,int low,int high){
int pivotloc;
if(low<high){
pivotloc=Partition(L,low,high);
QSort(L,low,pivotloc-1);
QSort(L,pivotloc+1,high);
}
}
void QuickSort(SqList&L){
QSort(L,1,L.length);
}
int main(int argc, char *argv[])
{
int i,j;
SqList L;
printf("input the line of numbers:");
scanf("%d",&j);
for(i=0;j!=0&&i<=MAXSIZE;){
L.r[++i].key=j;
scanf("%d",&j);
}
L.length=i;
QuickSort(L);
printf("Output the line is: ");
for(i=1;i<=L.length;i++)
printf("%d ",L.r[i].key);
printf("\n");
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -