基本排序的几种算法总结
上一篇 / 下一篇 2007-07-04 13:57:14 / 个人分类:将测试进行到底
#include <stdio.h>
'B${Nu"[cIAY0#include <time.h>51Testing软件测试网8Ml|$U0^
#include<stdlib.h>51Testing软件测试网}$tW5~%h_q5a_a
#include<dos.h>
*zw+JreNhl0#define n 10000
([n1Zb_g7u%`0typedef int keytype;51Testing软件测试网H[8vHz(lq
typedef struct{
g-M:F+VF9S3p0 keytype key;
3N7O3wm:{h0 }rectype;//待排序的文件的记录类型51Testing软件测试网0KjmIon c
typedef rectype seqlist[n+1];
&~,l3c h|kk:m0seqlist r;51Testing软件测试网deK5w7DYT7e7yL,w
int m;
~6i\%F-wl0main()//主程序51Testing软件测试网u;Y0R2v\7sZ*i2A:e_
{
w|'PN G6U'ta {0 int i,j;
,P6p.Ps+qjX R051Testing软件测试网hP!r3P+tiM
//选择一种数据输入形式
JE.Dc:uTS0 printf("1---random data\n");
'_.^%a Mb`0 printf("2---inscre data\n");51Testing软件测试网;h9C;J o$y]G
printf("3---descre data\n");
[$Qt6^0C0 printf("4---input data\n");51Testing软件测试网4EgC%z%K Q$c
scanf("%d",&j);
4H)vA/v\0 if (j==1) randoming();//产生一组随机数据51Testing软件测试网u(Q'G1B3{(z#Q
51Testing软件测试网.D4Z4c^Mm
if (j==2)//产生一组递增序列
)S|^W^3f/o4T9Q0 for (m=1;m<=n;m++)
wy5|"d:?(KsC0 r[m].key=m;51Testing软件测试网6^'gTd?'A7d
51Testing软件测试网$pd:g6T3JDoa
if (j==3)//产生一组递减序列
[5j t,T!v t0 for(m=1;m<=n;m++)51Testing软件测试网G)s%_3Bk5q
r[m].key=n-m+1;
7S`6]y(g?#f-t051Testing软件测试网)z7c;p9G1FE:Y{
if (j==4){//由用户自己输入数据序列,设这组数据中不含0,以0作为结束
s9T6lerm0 printf("please input the sort data:(end of 0)\n");
QN2pwcr.z0 r[0].key=1;
R6^Y A;gb0 m=0;51Testing软件测试网O6Bf!w^\4e
while((m<=n)&&(r[m].key)){
#A3J-Yz Z0 m++;51Testing软件测试网,E W7]\3]F'xg@G
scanf("%d",&(r[m].key));
7D I#?X+c0 }//end of while51Testing软件测试网'GmeFb v
m--;51Testing软件测试网_Q6{"J*^&yj
}//end of if
R!V*|SEn"t3L,x0
KQ a+sg%ot{2d O0 printf("1-----insertsort\n");
9xxm _8zOP0 printf("2-----bubblesort\n");51Testing软件测试网/BGv x-yr/Z
printf("3-----selectsort\n");51Testing软件测试网%CK8X m lIF
printf("4-----quicksort\n");51Testing软件测试网@\1B*Dp#E
printf("5-----heapsort\n");
j#W&V^TF0 scanf("%d",&j);51Testing软件测试网F p7bcR,T1O
Z ~{wbx0 //输出排序前的序列
@ DHly Gu7X9l0 printf("the source data:\n");
'B${Nu"[cIAY0#include <time.h>51Testing软件测试网8Ml|$U0^
#include<stdlib.h>51Testing软件测试网}$tW5~%h_q5a_a
#include<dos.h>
*zw+JreNhl0#define n 10000
([n1Zb_g7u%`0typedef int keytype;51Testing软件测试网H[8vHz(lq
typedef struct{
g-M:F+VF9S3p0 keytype key;
3N7O3wm:{h0 }rectype;//待排序的文件的记录类型51Testing软件测试网0KjmIon c
typedef rectype seqlist[n+1];
&~,l3c h|kk:m0seqlist r;51Testing软件测试网deK5w7DYT7e7yL,w
int m;
~6i\%F-wl0main()//主程序51Testing软件测试网u;Y0R2v\7sZ*i2A:e_
{
w|'PN G6U'ta {0 int i,j;
,P6p.Ps+qjX R051Testing软件测试网hP!r3P+tiM
//选择一种数据输入形式
JE.Dc:uTS0 printf("1---random data\n");
'_.^%a Mb`0 printf("2---inscre data\n");51Testing软件测试网;h9C;J o$y]G
printf("3---descre data\n");
[$Qt6^0C0 printf("4---input data\n");51Testing软件测试网4EgC%z%K Q$c
scanf("%d",&j);
4H)vA/v\0 if (j==1) randoming();//产生一组随机数据51Testing软件测试网u(Q'G1B3{(z#Q
51Testing软件测试网.D4Z4c^Mm
if (j==2)//产生一组递增序列
)S|^W^3f/o4T9Q0 for (m=1;m<=n;m++)
wy5|"d:?(KsC0 r[m].key=m;51Testing软件测试网6^'gTd?'A7d
51Testing软件测试网$pd:g6T3JDoa
if (j==3)//产生一组递减序列
[5j t,T!v t0 for(m=1;m<=n;m++)51Testing软件测试网G)s%_3Bk5q
r[m].key=n-m+1;
7S`6]y(g?#f-t051Testing软件测试网)z7c;p9G1FE:Y{
if (j==4){//由用户自己输入数据序列,设这组数据中不含0,以0作为结束
s9T6lerm0 printf("please input the sort data:(end of 0)\n");
QN2pwcr.z0 r[0].key=1;
R6^Y A;gb0 m=0;51Testing软件测试网O6Bf!w^\4e
while((m<=n)&&(r[m].key)){
#A3J-Yz Z0 m++;51Testing软件测试网,E W7]\3]F'xg@G
scanf("%d",&(r[m].key));
7D I#?X+c0 }//end of while51Testing软件测试网'GmeFb v
m--;51Testing软件测试网_Q6{"J*^&yj
}//end of if
R!V*|SEn"t3L,x0
KQ a+sg%ot{2d O0 printf("1-----insertsort\n");
9xxm _8zOP0 printf("2-----bubblesort\n");51Testing软件测试网/BGv x-yr/Z
printf("3-----selectsort\n");51Testing软件测试网%CK8X m lIF
printf("4-----quicksort\n");51Testing软件测试网@\1B*Dp#E
printf("5-----heapsort\n");
j#W&V^TF0 scanf("%d",&j);51Testing软件测试网F p7bcR,T1O
Z ~{wbx0 //输出排序前的序列
@ DHly Gu7X9l0 printf("the source data:\n");