/*
============================================================================
Name : quick_sort.c
Author : Cly
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX 101
int a[MAX]; //定义全局数组,小型方便测试
void quicksort(int left,int right) //每次进入的左、右边界
{
int i,j,t,tmp;
if(left>right)
return;
tmp=a[left];
i=left;
j=right;
while(i!=j)
{
while(a[j]>=tmp&&j>i)
--j;
while(a[i]<=tmp&&i<j)
++i;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
a[left]=a[i];
a[i]=tmp;
quicksort(left,i-1); //递归处理左边的
quicksort(i+1,right); //递归处理右边的
return;
}
int main(void) {
puts("!!!quick_sort!!"); /* prints !!!quick_sort!! */
freopen("./in.txt","r",stdin);
int i,n;
scanf("%d",&n); //从 stdin 输入数据
for(i=1;i<=n;++i)
scanf("%d",&a[i]);
quicksort(1,n); //快速排序调用
for(i=1;i<=n;++i) //排序输出后的结果
printf("%d ",a[i]);
fclose(stdin);
return EXIT_SUCCESS;
}
============================================================================
Name : quick_sort.c
Author : Cly
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX 101
int a[MAX]; //定义全局数组,小型方便测试
void quicksort(int left,int right) //每次进入的左、右边界
{
int i,j,t,tmp;
if(left>right)
return;
tmp=a[left];
i=left;
j=right;
while(i!=j)
{
while(a[j]>=tmp&&j>i)
--j;
while(a[i]<=tmp&&i<j)
++i;
if(i<j)
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
a[left]=a[i];
a[i]=tmp;
quicksort(left,i-1); //递归处理左边的
quicksort(i+1,right); //递归处理右边的
return;
}
int main(void) {
puts("!!!quick_sort!!"); /* prints !!!quick_sort!! */
freopen("./in.txt","r",stdin);
int i,n;
scanf("%d",&n); //从 stdin 输入数据
for(i=1;i<=n;++i)
scanf("%d",&a[i]);
quicksort(1,n); //快速排序调用
for(i=1;i<=n;++i) //排序输出后的结果
printf("%d ",a[i]);
fclose(stdin);
return EXIT_SUCCESS;
}