数据结构课程设计——排序与查找

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

北京信息科技大学

课程设计报告

课程名称数据结构课程设计

题目排序与查找

指导教师赵庆聪

设计起止日期

设计地点

系别信息管理学院

专业__信息管理与信息系统_

姓名/学号______鲁丹2012012108__

b=SelectSort(L);

display(L);

printf("此排序法关键字比较的次数为:%d\n",b);

printf("\n快速排序输出的顺序表为:\n");

c=QuickSort(L,1,20);

display(L);

printf("此排序法关键字比较的次数为:%d\n",c); printf("\n双向起泡法排序输出的顺序表为:\n");

d=BubbleSort(L);

display(L);

printf("此排序法关键字比较的次数为:%d\n",d);

}

1.#include "stdio.h"

2.#include "stdlib.h"

3.#include "string.h"

4.#include "time.h"

5.#include "limits.h"

6.#define MAXITEM 1000

7.typedef int KeyType,ElemType;

8.int count1=0,count2=0,count3=0,count4=0,count5=0,count6=0;

9.int swap1=0,swap2=0,swap3=0,swap4=0,swap5=0,swap6=0;

10.typedef struct rec

11.{

12. KeyType key;

13. ElemType data;

14.}sqlist[MAXITEM];

15.

16.void gennum(sqlist r,sqlist t,int n)

17.{

18.int i;

19. srand((unsigned)time(NULL));

20.for(i=1;i<=n;i++)

21. { t[i].key=rand()%100;

22. r[i].key=t[i].key;

23. }

24.}

25.

26.void ini(sqlist r,sqlist t,int n)

27.{

28.int i;

29.for(i=1;i<=n;i++)

30. r[i].key=t[i].key;

31.}

32.

33.void BubbleSort(sqlist r,int n)//起泡法r[1]~r[n]

34.{

35.int i,j;

36.struct rec w;

37.for(i=1;i<=n-1;i++)

38.for(j=n;j>=i+1;j--)

39. {

40.if(r[j].key

41. {

42. w=r[j];

43. r[j]=r[j-1];

44. r[j-1]=w;

45. swap1++;

46. }

47. count1++;

48. }

49.

50.}

51.

52.

53.void InsertSort(sqlist r,int n)//直接插入排序r[1]~r[n]

54.{

55.int i,j;

56.for(i=2;i<=n;i++)

57. {

58. count2++;

59. r[0]=r[i];

60. j=i-1;

61.while(r[0].key

62. {

63. r[j+1]=r[j];

64. j--;

65. count2++;

66. swap2++;

67. }

68. r[j+1]=r[0];

69. swap2++;

70. }

71.}

72.

73.void SelectSort(sqlist r,int n)//简单选择排序r[1]~r[n]

74.{

75.int i,j,k;

76.struct rec temp;

77.for(i=1;i<=n-1;i++)

78. {

79. k=i;

80.for(j=i+1;j<=n;j++)

81.if(r[j].key

82.if(i!=k)

83. {

84. temp=r[i];

85. r[i]=r[k];

86. r[k]=temp;

87. swap3++;

88. }

89. }

90.}

91.

92.void QuickSort(sqlist r,int s,int t)//快速排序r[s]~r[t],r[0]空出

93.{

94.int i=s,j=t;

95.if(s

96. {

相关文档
最新文档