数据结构实验源代码Word文档格式.docx
- 文档编号:4877272
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:42
- 大小:21.11KB
数据结构实验源代码Word文档格式.docx
《数据结构实验源代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构实验源代码Word文档格式.docx(42页珍藏版)》请在冰点文库上搜索。
FD=-1\n"
);
while(f!
=-1){
e=L->
elem+n;
if(L->
length==L->
listsize)
{
elem=(ET*)realloc(L->
elem,(LIST_SIZE+LIST_ADD)*sizeof(ET));
(L->
length)+=LIST_ADD;
listsize)+=LIST_ADD;
}
else
length=(L->
length)+LIST_ADD;
L->
elem+n:
%d
n=%d\n"
L->
elem+n,L->
length,n);
name:
num:
scorePD:
\n"
scanf("
%s%d%d"
&
e->
nam,&
num,&
score);
%s\tnum:
%d\tscore:
date=%dlength=%d\n"
e->
nam,e->
num,e->
score,L->
length);
\nFD:
"
%d"
f);
n+=LEN;
k++;
sum+=e->
score;
average=sum/k;
/*输出顺序表*/
voidprint(SqList*L)
inti=1,n=0;
\n%d\n"
while(i<
=L->
length)
date=%dlength=%d\n"
elem+LEN,L->
i++;
\nsum=%d\taverage=%.2f\n"
sum,average);
/*主函数*/
voidmain(){
root=creat(p);
input(p);
print(p);
getch();
实验三
#include<
stdio.h>
stdlib.h>
malloc.h>
#defineLIST_SIZE5
#defineLIST_ADD1
string.h>
typedefstruct{
charnum[10];
charnam[20];
}ElemType;
/*dimElemType*/
typedefstructstu{
ElemType*elem;
}List;
/*creatakonglist*/
voidCreatList(List*L){
success\n"
elem=(ElemType*)malloc(LIST_SIZE*sizeof(ElemType));
if(!
elem)exit(0);
voidListInseart(List*L){
intLocate;
ElemType*p1,*p2,e;
whichplaceyouwanttoinseart?
Locate);
inputtheinseartingelemet:
%s%s%d"
e.num,e.nam,&
e.score);
if(Locate<
1||Locate>
length){
error\n"
exit(0);
/*lengthislongerthansizetomaxersize*/
listsize){
elem=(ElemType*)realloc(L->
elem,(L->
listsize+LIST_ADD)*sizeof(ElemType));
listsize+=LIST_ADD;
p2=L->
elem+Locate-1;
for(p1=L->
elem+L->
length-1;
p1>
=p2;
p1--)*(p1+1)=*p1;
*(p2)=e;
length++;
voidInputData(List*L){
ElemTypee;
intn=0;
inputstudent'
snumber,name,score,atmost5students\n"
suchas001chengfeng89\n"
while(e.score>
0){
*(L->
elem+n)=e;
n++;
inputaelement,ifyouwanttostop,intputthescorewhichis<
0;
suchas;
aa-1\n"
length=n;
voidVisitList(List*L){
inti;
theelementsarethese:
for(i=0;
i<
length;
i++){
%s\t%s\t%d\n"
(L->
elem+i)->
num,(L->
nam,(L->
voidListDel(List*L){
inti,j;
whiceelementyouwanttodelet,inputthename:
%s"
e.nam);
if(strcmp((L->
nam,e.nam)==0){
for(j=i+1;
j<
j++){
elem+j-1)=*(L->
elem+j);
length--;
i--;
voidmain(){
intchoose=0;
warning:
youmustchoose1,thenchoose2,thenyoujustcanchooseothers.\n"
do{
1.creatthetable.\n"
2.inputdataforthetable.\n"
3.inseartaelementinthetable.\n"
4.deletaelementinthetable.\n"
5.visitthetable.\n"
6.exit.\n"
inputyourchoose:
choose);
switch(choose){
case1:
CreatList(p);
break;
case2:
InputData(p);
case3:
ListInseart(p);
case4:
ListDel(p);
case5:
VisitList(p);
default:
printf("
exit!
!
}while(choose>
0&
&
choose<
6);
实验四
#defineNULL0
typedefstructstudent{
structstudent*next;
}LinkList;
LinkList*head;
voidInitList();
voidClearList();
voidListInsert();
voidListDelete();
voidListTraverse();
intn;
do{
inputyourchoose.\n"
1.creatalinklist\n"
2.clearthelinklist\n"
3.insertalinklist\n"
4.deletealist.\n"
5.vistthelist.\n"
6.exit!
n);
switch(n){
InitList();
ClearList();
ListInsert();
ListDelete();
ListTraverse();
}while(n<
6&
n>
0);
voidInitList(){
head=(LinkList*)malloc(sizeof(LinkList));
if(head==NULL){
failure\n"
head->
next=NULL;
creatingisok!
pressanykeytocontinue\n"
voidListTraverse(){
LinkList*p;
p=head->
next;
while(p!
=NULL){
p->
num,p->
nam,p->
p=p->
voidClearList(){
strcpy(head->
num,"
01"
nam,"
bai"
score=-1;
clearingisok!
voidListInsert(){
LinkList*p,*q,*p1;
p=(LinkList*)malloc(sizeof(LinkList));
p1=head;
while(p1->
next!
p1=p1->
inputtheelements,suchas:
01li79\n"
p->
p1->
next=p;
p->
done,pressanykeytocontinue\n"
voidListDelete(){
LinkList*p2,*q,*p1;
inputthewhichyouwanttodeletbasedthename?
nam);
p2=head;
p1=head->
while(p1!
if(strcmp(p1->
nam,nam)==0){
q=p1;
p2->
next=p1;
free(q);
else{
p2=p1;
done,pressanykeytocontinue.\n"
实验五
#defineSTACK_SIZE10
#defineSTACKINCREMENT5
typedef
charcElemType;
typedeffloatiElemType;
iElemType*base;
iElemType*top;
intstacksize;
}istack;
cElemType*base;
cElemType*top;
}cstack;
istack*s1;
cstack*s2;
charsituation1='
n'
;
charsituation2='
inttable[7][7];
voidInitStack();
voidClearStack();
voidStackEmpty();
voidStackTraverse();
voidStack1Push(floatn);
voidStack2Push(charc);
voidStackLength();
intHL(charc);
intope(charc1);
charStack2Get();
floatStack1Get();
voidop_table();
voidqiu_zhi();
intchoose;
op_table();
1.Initastack.\n"
2.Clearthestack.\n"
3.judgeifthestackisempty.\n"
4.toknowthelengthofthestack.\n"
5.visitthedata.\n"
6.inputanexpressionandtoitsvalue.\n"
7.exit.\n"
InitStack();
ClearStack();
StackEmpty();
StackLength();
StackTraverse();
case6:
qiu_zhi();
7);
exit.\n"
/*prepareparts*/
voidInitStack(){
s1=(istack*)malloc(sizeof(istack));
s1->
base=(float*)malloc(STACK_SIZE*sizeof(int));
s2=(cstack*)malloc(sizeof(cstack));
s2->
base=(char*)malloc(STACK_SIZE*sizeof(char));
stacksize=s2->
stacksize=STACK_SIZE;
top=s1->
base;
top=s2->
voidClearStack(){
2;
*(s1->
base+i)=9;
*(s2->
base+i)='
$'
*s2->
top='
#'
top++;
voidStackEmpty(){
if(s1->
top==s1->
base)situation1='
y'
if(s2->
top==s2->
base)situation2='
stack1is%c\n"
situation1);
stack2is%c\n"
situation2);
voidStackTraverse(){
float*p1;
char*p2;
p1=s1->
top;
p2=s2->
while(p1>
s1->
base){
p1--;
%d"
*p1);
while(p2>
s2->
p2--;
%c"
*p2);
/*operateparts*/
voidStack1Push(floatn){
top-s1->
base==s1->
stacksize){
s1_size\n"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 实验 源代码