数据结构 排序算法设计和比较

麻烦给下面的程序添加注释,越详细越好~谢谢

#include<stdio.h>
/*cha ru*/
void InsertSort (int a[], int n)
{int i=0;
int j=0;
for (i=2; i<=n; i++)
{ a[0]=a[i];
j=i-1;
while (a[0]<a[j])
{
a[j+1]=a[j];
j=j-1;
}
a[j+1]=a[0];
}

}

/*kuai su*/
void quicksort (int a[], int first, int end )
{int i=0;
int j=0;
int temp;
i=first; j=end; temp=a[i];
while(i<j)
{
while (i<j && temp<= a[j]) j--;
a[i]=a[j];
while (i<j && a[i]<=temp) i++;
a[j]=a[i];
}
a[i]=temp;
if (first<i-1) quicksort(a, first, i-1);
if (i+1<end) quicksort(a, i+1, end);
}

/*mao bao*/
void msort(int a[],int n)
{int i=0;
int j=0;
int t=0;
for(i=1;i<=n;i++)
{for(j=i+1;j<=n;j++)
{if(a[i]>a[j])
{t=a[i];
a[i]=a[j];
a[j]=t;

}

}
}
}

void main()
{int b[20];
int i=0;
int n=0;
printf("input the number of data:\n");
scanf("%d",&n);
printf("input the data:\n");
for(i=1;i<=n;i++)
{scanf("%d",&b[i]);
}
InsertSort (b,n);
printf("the result of cha ru bai xu\n");
for(i=1;i<=n;i++)
printf("%d ",b[i]);

quicksort (b, 1,n );
printf("\nthe result of kuaisu bai xu\n");
for(i=1;i<=n;i++)
printf("%d ",b[i]);

msort(b,n);
printf("\nthe result of maobao bai xu\n");
for(i=1;i<=n;i++)
printf("%d ",b[i]);

getch();
}
问题描述:利用直接插入排序、冒泡排序、快速排序对数列进行排序。
基本要求:
(1) 能随机生成30个值为0到100的数。
(2) 用于排序的输入数列可以是要求(1)中随机生成的,也可以是键盘输入。
(3) 输出结果为利用三种方法排序后的结果,并能显示三种算法时间、空间性能参数值。

第1个回答  2008-12-06
麻烦告诉我是干什么用的,谢谢
相似回答