验证性实验Word下载.docx
- 文档编号:22170388
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:12
- 大小:16.50KB
验证性实验Word下载.docx
《验证性实验Word下载.docx》由会员分享,可在线阅读,更多相关《验证性实验Word下载.docx(12页珍藏版)》请在冰豆网上搜索。
}bsnode;
typedefstructLnode
{
intdata;
structLnode*next;
}Lnode,*ListLink;
//建立链表结点
typedefstruct
intpos;
ListLinkfirstnode;
//建立数组结点
}HashBox;
typedefstruct
HashBoxHArrary[INIT_MAXSIZE];
//建立哈希数组(哈希表的地址表头)
}HashArray;
3.算法设计
4.界面设计
5.运行、测试
(一)顺序查找验证
(1)运行程序,显示菜单
(2)输入n
(3)输出结果
(1)运行程序,显示菜单
(2)输入n
(3)输出结果
6.实验收获及思考
建立哈希表时没有考虑冲突处理问题,做程序时要谨慎小心。
附录:
源代码
#include<
stdio.h>
stdlib.h>
#defineMAX_LENGTH100
typedefintKeyType;
typedefstruct{
}SSTable;
intSearch_Seq(SSTableST,KeyTypekey){
inti;
ST.elem[0]=key;
//“哨兵”
for(i=ST.length;
ST.elem[i]!
=key;
i--)
;
//从后往前找
returni;
//找不到时,i为0
}
voidmain()
inti,key;
SSTableT;
T.elem=(KeyType*)malloc(sizeof(KeyType));
printf("
输入数据个数\n"
);
scanf("
%d"
&
T.length);
for(i=1;
i<
=T.length;
i++){
输入数据%d;
\n"
i);
T.elem[i]);
}
for(i=1;
i++)
%5d"
T.elem[i]);
\n输入要查找的数据\n"
key);
i=Search_Seq(T,key);
位置是%d\n"
i);
system("
pause"
#include<
#defineOK1
#defineERROR0
intscore[100];
输入数据个数:
\n"
&
length);
for(inti=1;
i<
=length;
i++)
{printf("
输入第%d个元素"
scanf("
score[i]);
\n输入要查找的关键字\n"
intlow,high,mid;
low=1;
high=length;
while(low<
=high)
{
mid=(low+high)/2;
if(score[mid]==key)//找到待查元素
{printf("
数据位置%d"
mid);
system("
}
elseif(key<
score[mid])
high=mid-1;
//继续在前半区间进行查找
elseif(key>
low=mid+1;
//继续在后半区间进行查找
无此数据"
typedefintdatatype;
typedefstructnode
typedefbsnode*bstree;
voidinsertbstree(bstree*t,datatypex)
bstreef,p;
p=*t;
while(p)
f=p;
if(x<
p->
key)
p=p->
lchild;
else
rchild;
p=(bstree)malloc(sizeof(bsnode));
key=x;
lchild=p->
rchild=NULL;
if(*t==NULL)
*t=p;
else
(f->
key))
f->
lchild=p;
rchild=p;
}
bstreecreatbstree(bstreet)
while(key!
=-1)
insertbstree(&
t,key);
returnt;
voidinorder(bstreet)
if(t)
{
inorder(t->
lchild);
%d"
t->
rchild);
}
voidqorder(bstreet)
{if(t)
qorder(t->
voidhorder(bstreet)
if(t)
horder(t->
}
intmain()
bstreet=NULL,p;
请输入一个-1为结束标记的结点序列:
p=creatbstree(t);
printf("
中序遍历:
"
inorder(p);
先序遍历:
qorder(p);
后序遍历:
horder(p);
return0;
malloc.h>
#defineINIT_MAXSIZE10
voidInitHashList(HashArray&
l,intinput[],intaccount);
//建立哈希表
voidVistHashList(HashArray&
l);
//遍历输出哈希表
intmain(void)
{intaccount=0,i=0,input[256];
HashArrayl;
printf("
请输入要插入哈希表元素的个数:
scanf("
account);
请输入要插入哈希表的元素:
for(i=0;
i<
account;
i++)
{scanf("
input[i]);
InitHashList(l,input,account);
\n哈希表如下:
VistHashList(l);
return0;
l,intinput[],intaccount)//建立哈希表
{inti=0,j=0,pos=0;
ListLinkq,p;
charch='
A'
;
for(i=0;
INIT_MAXSIZE;
i++)//初始化哈希表头
{l.HArrary[i].pos=ch++;
l.HArrary[i].firstnode=NULL;
{pos=input[i]%INIT_MAXSIZE;
//计算元素地址
q=newLnode;
//申请结点
q->
data=input[i];
next=NULL;
if(l.HArrary[pos].firstnode==NULL)//判断当前地址表头是否还没有元素连入
l.HArrary[pos].firstnode=q;
else
{p=l.HArrary[pos].firstnode;
while(p->
next!
=NULL)
{p=p->
next;
//找到链表表尾
}
p->
next=q;
//将要插入的结点接入表尾
}
l)//输出哈希表
{ListLinkp;
%c."
l.HArrary[i].pos);
p=l.HArrary[i].firstnode;
while(p!
{printf("
->
p->
data);
p=p->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 验证 实验
![提示](https://static.bdocx.com/images/bang_tan.gif)