数据结构课程设计排序与查找本科论文文档格式.docx
- 文档编号:14541146
- 上传时间:2022-10-23
- 格式:DOCX
- 页数:17
- 大小:19.34KB
数据结构课程设计排序与查找本科论文文档格式.docx
《数据结构课程设计排序与查找本科论文文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计排序与查找本科论文文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
#defineLIST_INIT_SIZE100
#defineLISTINCREMENT10
#defineINFEASIBLE-1
#defineOVERFLOW-2
typedefintStatus;
typedefintElemType;
typedefstruct{
ElemType*elem;
intlength;
intlistsize;
}List;
StatusInitList(List&
L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
L.length=0;
L.listsize=LIST_INIT_SIZE;
returnOK;
}//InitList
voidCreate(List&
L,intn)
inti;
srand(time(NULL));
for(i=0;
i<
n;
i++)
{
L.elem[i]=rand()%N;
L.length++;
printf("
%d"
L.elem[i]);
}
\n"
);
}
intInsertSort(ListL)
inti,j,t,m;
m=0;
for(i=1;
L.length;
t=L.elem[i];
j=i-1;
if(t>
=L.elem[j])
m++;
else
while((j>
=0)&
&
(t<
L.elem[j]))
{
L.elem[j+1]=L.elem[j];
j--;
}
L.elem[j+1]=t;
returnm;
intSelectSort(ListL)
inti,j,k,min,t=0;
min=i;
for(j=i+1;
j<
j++)
if(L.elem[j]<
L.elem[min])
{
min=j;
t++;
}
elset++;
if(min!
=i)
k=L.elem[i];
L.elem[i]=L.elem[min];
L.elem[min]=k;
returnt;
intQuickSort(ListL,ints,intt)
{
inti=s,j=t,count4=0;
if(s<
t)
{
L.elem[0]=L.elem[s];
do
while(j>
i&
L.elem[j]>
=L.elem[0])
j--;
count4++;
}
if(i<
j)
L.elem[i]=L.elem[j];
i++;
}
while(i<
j&
L.elem[i]<
i++;
L.elem[j]=L.elem[i];
j--;
while(i<
j);
L.elem[i]=L.elem[0];
QuickSort(L,s,j-1);
QuickSort(L,j+1,t);
returncount4;
}
intBubbleSort(ListL)
intflag,i,j;
intt=0;
flag=1;
while(flag==1)
flag=0;
i=0;
for(j=L.length-i;
j>
i;
j--)
if(L.elem[j-1]>
L.elem[j])
flag=1;
intm;
m=L.elem[j];
L.elem[j]=L.elem[j-1];
L.elem[j-1]=m;
voiddisplay(ListL)
voidmain()
ListL;
intlow,high,a,b,c,d;
InitList(L);
请将随机产生的0-100间的20个数输出:
Create(L,20);
\n直接插入法排序输出的顺序表为:
a=InsertSort(L);
display(L);
此排序法关键字比较的次数为:
%d\n"
a);
\n直接选择法排序输出的顺序表为:
b=SelectSort(L);
b);
\n快速排序输出的顺序表为:
c=QuickSort(L,1,20);
c);
\n双向起泡法排序输出的顺序表为:
d=BubbleSort(L);
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.
19.
srand((unsigned)time(NULL));
20.
for(i=1;
=n;
i++)
21.
{
t[i].key=rand()%100;
22.
r[i].key=t[i].key;
23.
}
24.}
25.
26.void
ini(sqlist
27.{
28.
29.
30.
31.}
32.
33.void
BubbleSort(sqlist
r,int
n)//起泡法r[1]~r[n]
34.{
35.
i,j;
36.
w;
37.
=n-1;
38.
for(j=n;
=i+1;
j--)
39.
40.
if(r[j].key<
r[j-1].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
n)//直接插入排序r[1]~r[n]
54.{
55.
56.
for(i=2;
57.
58.
count2++;
59.
r[0]=r[i];
60.
j=i-1;
61.
while(r[0].key<
r[j].key)
62.
63.
r[j+1]=r[j];
64.
j--;
65.
66.
swap2++;
67
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 课程设计 排序 查找 本科 论文