quick_sort.h 包含头文件、函数声明
#include<stdio.h>
int quick_sort(int *s,int low,int high);
int sort(int *s,int low,int high);
int p_sort(int *s,int data);
quick_sort.c 包含函数的定义
#include"quick_sort.h"
int quick_sort(int *s,int low,int high){
if(NULL==s){
printf("入参为空,请检查..\n");
return -1;
}
if(low<high){
int temp=sort(s,low,high);
quick_sort(s,low,temp-1);
quick_sort(s,temp+1,high);
}
}
int sort(int *s,int low,int high){
int pivot=s[low];
while(low<high){
while(low<high&&s[high]>=pivot)--high;
s[low]=s[high];
while(low<high&&s[low]<=pivot)++low;
s[high]=s[low];
}
s[low]=pivot;
return low;
}
int p_sort(int *s,int data){
int i=0;
for(i=0;i<data;i++){
printf("%d ",s[i]);
}
printf("\n");
}
quick.main.c 程序入口
#include"quick_sort.h"
int main(int argc,const int *argv[]){
int s[30]={0};
int i=0;
printf("请输入想要排序得数字,9999结束:");
while(scanf("%d",&s[i])){
if(9999==s[i]){
break;
}
printf("请输入:");
i++;
}
int high=i-1;
p_sort(s,i);
quick_sort(s,0,high);
p_sort(s,i);
return 0;
}