简单选择排序/*对整型数组的元素进行简单选择排序(源程序的整型简单选择排序)*/ #include<stdio.h>#include<conio.h>#define N 6void taxis(int b[],int k){int i,j,temp;for(i=0;i<k-1;i++)for(j=i+1;j<k;j++)if(b[i]>b[j]){temp=b[i];b[i]=b[j];b[j]=temp;}}void main(){int a[N]={9,8,5,6,2,0},i;clrscr();taxis(a,N);for(i=0;i<N;i++){printf("%d",a[i]);if(i<N-1)printf(",");}}/*对整型数组的元素进行简单选择排序(源程序的整型排序-指针))*/#include<stdio.h>#include<conio.h>#define N 6void taxis(int *p1,int k){int temp,*p2,*p3;for(p2=p1;p2<p1+k-1;p2++)for(p3=p2+1;p3<p1+k;p3++)if(*p2>*p3){temp=*p2;*p2=*p3;*p3=temp;}}void main(){int a[N]={9,8,5,6,2,0},*p;clrscr();taxis(a,N);for(p=a;p<a+N;p++)printf("%d",*p);if(p<a+N-1)printf(",");}}/*将字符串按其的长度(字母对应的ASCⅡ值由小到大)进行简单选择排序(源程序的字符串长度排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char *p1[],int k){int i,j;char *temp;for(i=0;i<k-1;i++)for(j=i+1;j<k;j++)if(strlen(p1[i])>strlen(p1[j])){temp=p1[i];p1[i]=p1[j];p1[j]=temp;}}void main(){char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行简单选择排序(源程序的字符串顺序排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char *p1[],int k){int i,j;char *temp;for(i=0;i<k-1;i++)for(j=i+1;j<k;j++)if(strcmp(p1[i],p1[j])>0){temp=p1[i];p1[i]=p1[j];p1[j]=temp;}}{char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将整型数组的元素进行简单选择排序(终端输入的整型排序),如果连续出现3个为0的数据,*//*则默认判断这3个为0的数据无效以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 50void taxis(int b[],int k){int i,j,temp;for(i=0;i<k-1;i++)for(j=i+1;j<k;j++)if(b[i]>b[j]){if(b[j]==0&&b[j+1]==0&&b[j+2]==0)break;else{temp=b[i];b[i]=b[j];b[j]=temp;}}}void main(){int a[N]={0},i;clrscr();printf("please input no more than %d int datas:\n",N);for(i=0;i<N;i++)scanf("%d",&a[i]);taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){printf("%d",a[i]);if(a[i+1]==0&&a[i+2]==0&&a[i+3]==0)break;printf(",");}}/*将整型数组的元素进行简单选择排序(终端输入的整型排序-指针),如果连续出现3个为0的数据,*/ /*则默认判断这3个为0的数据以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 50void taxis(int *p1,int k){int temp,*p2,*p3;for(p2=p1;p2<p1+k-1;p2++)for(p3=p2+1;p3<p1+k;p3++)if(*p2>*p3){if(*p3==0&&*(p3+1)==0&&*(p3+2)==0)break;else{temp=*p2;*p2=*p3;*p3=temp;}}}void main(){int a[N]={0},*p;clrscr();printf("please input no more than %d int datas:\n",N);for(p=a;p<a+N;p++)scanf("%d",p);taxis(a,N);printf("The result of is:\n");for(p=a;p<a+N;p++){printf("%d",*p);if(*(p+1)==0&&*(p+2)==0&&*(p+3)==0)break;printf(",");}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行简单选择排序(终端输入的字符串顺序排序)*/ /*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char *p1[],int k){int i,j;char *temp;for(i=0;i<N;i++)for(j=i+1;j<k;j++)if(strlen(p1[i])>strlen(p1[j])&&strlen(p1[j])!=0){temp=p1[i];p1[i]=p1[j];p1[j]=temp;}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行简单选择排序(终端输入的字符串顺序排序)*/ /*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char *p1[],int k){int i,j;char *temp;for(i=0;i<k;i++)for(j=i+1;j<k;j++)if(strcmp(p1[i],p1[j])>0&&strlen(p1[j])!=0){temp=p1[i];p1[i]=p1[j];p1[j]=temp;}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}选择排序/*对整型数组的元素进行选择排序(源程序的整型排序)*/ #include<stdio.h>#include<conio.h>#define N 6void taxis(int b[],int k){int i,j,n,temp;for(i=0;i<k-1;i++){n=i;for(j=i+1;j<k;j++)if(b[n]>b[j])n=j;if(n!=i){temp=b[i];b[i]=b[n];b[n]=temp;}}}void main(){int a[N]={9,8,5,6,2,0},i;clrscr();taxis(a,N);for(i=0;i<N;i++){printf("%d",a[i]);if(i<N-1)printf(",");}}/*对整型数组的元素进行选择排序(源程序的整型排序-指针))*/#include<stdio.h>#include<conio.h>#define N 6void taxis(int *p1,int k){int i,temp,*p2,*p3;for(i=0;i<k-1;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(*p2>*p3)p2=p3;if(p2!=p1+i){temp=*(p1+i);*(p1+i)=*p2;*p2=temp;}}}void main(){int a[N]={9,8,5,6,2,0},*p;clrscr();taxis(a,N);for(p=a;p<a+N;p++){printf("%d",*p);if(p<a+N-1)printf(",");}}/*将字符串按其的长度(字母对应的ASCⅡ值由小到大)进行选择排序(源程序的字符串长度排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char **p1,int k){int i;char **p2,**p3,**temp;for(i=0;i<k-1;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(strlen(*p2)>strlen(*p3))p2=p3;if(p2!=p1+i){*temp=*(p1+i);*(p1+i)=*p2;*p2=*temp;}}}void main(){char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行选择排序(源程序的字符串顺序排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char **p1,int k){int i;char **p2,**p3,**temp;for(i=0;i<k-1;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(strcmp(*p2,*p3)>0)p2=p3;if(p2!=p1+i){*temp=*(p1+i);*(p1+i)=*p2;*p2=*temp;}}}void main(){char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将整型数组的元素进行选择排序(终端输入的整型排序),如果连续出现3个为0的数据,*//*则默认判断这3个为0的数据无效以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 10void taxis(int b[],int k){int i,j,n,temp;for(i=0;i<k-1;i++){n=i;for(j=i+1;j<k;j++)if(b[n]>b[j]){if(b[j]==0&&b[j+1]==0&&b[j+2]==0)break;elsen=j;}if(n!=i){temp=b[i];b[i]=b[n];b[n]=temp;}}}void main(){int a[N]={0},i;clrscr();printf("please input no more than %d int datas:\n",N);for(i=0;i<N;i++)scanf("%d",&a[i]);taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){printf("%d",a[i]);if(a[i+1]==0&&a[i+2]==0&&a[i+3]==0)break;printf(",");}}/*将整型数组的元素进行选择排序(终端输入的整型排序-指针),如果连续出现3个为0的数据,*/ /*则默认判断这3个为0的数据以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 50void taxis(int *p1,int k){int i,temp,*p2,*p3;for(i=0;i<k-1;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(*p2>*p3){if(*p3==0&&*(p3+1)==0&&*(p3+2)==0)break;elsep2=p3;}if(p2!=p1+i){temp=*(p1+i);*(p1+i)=*p2;*p2=temp;}}}void main(){int a[N]={0},*p;clrscr();printf("please input no more than %d int datas:\n",N);for(p=a;p<a+N;p++)scanf("%d",p);taxis(a,N);printf("The result of is:\n");for(p=a;p<a+N;p++){printf("%d",*p);if(*(p+1)==0&&*(p+2)==0&&*(p+3)==0)break;printf(",");}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行选择排序(终端输入的字符串顺序排序)*//*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char **p1,int k){int i;char **p2,**p3,**temp;for(i=0;i<k;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(strlen(*p2)>strlen(*p3)&&strlen(*p3)!=0)if(p2!=p1+i){*temp=*(p1+i);*(p1+i)=*p2;*p2=*temp;}}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行选择排序(终端输入的字符串顺序排序)*//*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char **p1,int k){int i;char **p2,**p3,**temp;for(i=0;i<k;i++){p2=p1+i;for(p3=p1+i+1;p3<p1+k;p3++)if(strcmp(*p2,*p3)>0&&strlen(*p3)!=0)p2=p3;if(p2!=p1+i){*temp=*(p1+i);*p2=*temp;}}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}起泡排序/*对整型数组的元素进行起泡排序(源程序的整型排序)*/ #include<stdio.h>#include<conio.h>#define N 6void taxis(int b[],int k){int i,j,temp;for(i=0;i<k-1;i++)for(j=0;j<k-1-i;j++)if(b[j]>b[j+1]){temp=b[j];b[j]=b[j+1];b[j+1]=temp;}}void main(){int a[N]={9,8,5,6,2,0},i;clrscr();taxis(a,N);for(i=0;i<N;i++){printf("%d",a[i]);if(i<N-1)printf(",");}}/*对整型数组的元素进行起泡排序(源程序的整型排序-指针))*/#include<stdio.h>#include<conio.h>#define N 6void taxis(int *p1,int k){int i,temp,*p2;for(i=0;i<k-1;i++){for(p2=p1;p2<p1+k-1-i;p2++)if(*p2>*(p2+1)){temp=*p2;*p2=*(p2+1);*(p2+1)=temp;}}}void main(){int a[N]={9,8,5,6,2,0},*p;clrscr();taxis(a,N);for(p=a;p<a+N;p++){printf("%d",*p);if(p<a+N-1)printf(",");}}/*将字符串按其的长度(字母对应的ASCⅡ值由小到大)进行起泡排序(源程序的字符串长度排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char **p1,int k){int i;char **p2,**temp;for(i=0;i<k-1;i++)for(p2=p1;p2<p1+k-1-i;p2++)if(strlen(*p2)>strlen(*(p2+1))){*temp=*p2;*p2=*(p2+1);*(p2+1)=*temp;}}void main(){char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行起泡排序(源程序的字符串顺序排序)*/ #include<stdio.h>#include<string.h>#include<conio.h>#define N 5void taxis(char **p1,int k){int i;char **p2,**temp;for(i=0;i<k-1;i++)for(p2=p1;p2<p1+k-1-i;p2++)if(strcmp(*p2,*(p2+1))>0){*temp=*p2;*p2=*(p2+1);*(p2+1)=*temp;}}void main(){char *a[]={"Follow","BASIC","Great","FORTRAN","Computer"};int i;clrscr();taxis(a,N);for(i=0;i<N;i++)printf("%s\n",a[i]);}/*将整型数组的元素进行起泡排序(终端输入的整型排序),如果连续出现3个为0的数据,*//*则默认判断这3个为0的数据无效以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 50void taxis(int b[],int k){int i,j,temp;for(i=0;i<k-1;i++)for(j=0;j<k-1-i;j++)if(b[j]>b[j+1]){if(b[j+1]==0&&b[j+2]==0&&b[j+3]==0)break;else{temp=b[j];b[j]=b[j+1];b[j+1]=temp;}}}void main(){int a[N]={0},i;clrscr();printf("please input no more than %d int datas:\n",N);for(i=0;i<N;i++)scanf("%d",&a[i]);taxis(a,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){printf("%d",a[i]);if(a[i+1]==0&&a[i+2]==0&&a[i+3]==0)break;printf(",");}}/*将整型数组的元素进行起泡排序(终端输入的整型排序-指针),如果连续出现3个为0的数据,*/ /*则默认判断这3个为0的数据以和其后面是没有数据,*//*即不输出这3个为0的数据以和其后面的数据(元素来自终端)*/#include<stdio.h>#include<conio.h>#define N 50void taxis(int *p1,int k){int i,temp,*p2;for(i=0;i<k-1;i++)for(p2=p1;p2<p1+k-1-i;p2++)if(*p2>*(p2+1)){if(*(p2+1)==0&&*(p2+2)==0&&*(p2+3)==0)break;else{temp=*p2;*p2=*(p2+1);*(p2+1)=temp;}}}void main(){int a[N]={0},*p;clrscr();printf("please input no more than %d int datas:\n",N);for(p=a;p<a+N;p++)scanf("%d",p);taxis(a,N);printf("The result of taxis is:\n");for(p=a;p<a+N;p++){printf("%d",*p);if(*(p+1)==0&&*(p+2)==0&&*(p+3)==0)break;printf(",");}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行起泡排序(终端输入的字符串顺序排序)*//*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char **p1,int k){int i;char **p2,**temp;for(i=0;i<k;i++)for(p2=p1;p2<p1+k-1-i;p2++)if(strlen(*p2)>strlen(*(p2+1))&&strlen(*(p2+1))!=0){*temp=*p2;*p2=*(p2+1);*(p2+1)=*temp;}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}/*将字符串按字母顺序(字母对应的ASCⅡ值由小到大)进行起泡排序(终端输入的字符串顺序排序)*//*当输入字符串时,遇到"回车"键则表示该字符串输入结束;当连续输入两个"回车键"时,则表示所有字符串输入结束*/#include<stdio.h>#include<string.h>#include<conio.h>#define N 50#define size 15void taxis(char **p1,int k){int i;char **p2,**temp;for(i=0;i<k;i++)for(p2=p1;p2<p1+k-1-i;p2++)if(strcmp(*p2,*(p2+1))>0&&strlen(*(p2+1))!=0){*temp=*p2;*p2=*(p2+1);*(p2+1)=*temp;}}void main(){ char a[size]={0},*p[N]={0};int i;clrscr();printf("Please input no more than %d strings\n",N);for(i=0;i<N;i++){gets(a);if(strlen(a)==0)break;p[i]=(char*)calloc(sizeof(a),sizeof(char));strcpy(p[i],a);}taxis(p,N);printf("The result of taxis is:\n");for(i=0;i<N;i++){if(strlen(p[i])==0)break;printf("%s\n",p[i]);}}快速排序//C语言中的快速排序//从终端输入不多于N个整型数据,然后将它们进行选择排序(从小到大),如果连续输入3个为0的数据, //则默认判断这3个为0的数据无效以和其后面是没有数据,*///即不输出这3个为0的数据以和其后面的数据#include <stdio.h>#define N 20void quick_sort(int data[], int low, int high){int i, j, pivot;if (low < high){pivot=data[low];i=low;j=high;while(i<j){while (i<j && data[j]>=pivot)j--;if(i<j)data[i++]=data[j];while (i<j && data[i]<=pivot)i++;if(i<j)data[j--]=data[i];}data[i]=pivot;quick_sort(data,low,i-1);quick_sort(data,i+1,high);}}int input_data(int data[]){int i,k;k=0;for(i=0;i<N;i++){scanf("%d",&data[i]);k++;if(k>=3&&data[i]==0&&data[i-1]==0&&data[i-2]==0){k-=3;break;}}return k;}void output_data(int data[],int m){int i;printf("The result of taxis is:\n");for(i=0;i<m;i++){printf("%d",data[i]);if(i+1<m)printf(",");if((i+1)%10==0)printf("\n");}printf("\n");}void main(){int n,data[N]={0};printf("please input no more than %d int datas:\n",N);n=input_data(data);quick_sort(data,0,n-1);output_data(data,n);}。