数据结构实验教案信息Word文档格式.docx

上传人:b****1 文档编号:1505183 上传时间:2023-04-30 格式:DOCX 页数:35 大小:44.30KB
下载 相关 举报
数据结构实验教案信息Word文档格式.docx_第1页
第1页 / 共35页
数据结构实验教案信息Word文档格式.docx_第2页
第2页 / 共35页
数据结构实验教案信息Word文档格式.docx_第3页
第3页 / 共35页
数据结构实验教案信息Word文档格式.docx_第4页
第4页 / 共35页
数据结构实验教案信息Word文档格式.docx_第5页
第5页 / 共35页
数据结构实验教案信息Word文档格式.docx_第6页
第6页 / 共35页
数据结构实验教案信息Word文档格式.docx_第7页
第7页 / 共35页
数据结构实验教案信息Word文档格式.docx_第8页
第8页 / 共35页
数据结构实验教案信息Word文档格式.docx_第9页
第9页 / 共35页
数据结构实验教案信息Word文档格式.docx_第10页
第10页 / 共35页
数据结构实验教案信息Word文档格式.docx_第11页
第11页 / 共35页
数据结构实验教案信息Word文档格式.docx_第12页
第12页 / 共35页
数据结构实验教案信息Word文档格式.docx_第13页
第13页 / 共35页
数据结构实验教案信息Word文档格式.docx_第14页
第14页 / 共35页
数据结构实验教案信息Word文档格式.docx_第15页
第15页 / 共35页
数据结构实验教案信息Word文档格式.docx_第16页
第16页 / 共35页
数据结构实验教案信息Word文档格式.docx_第17页
第17页 / 共35页
数据结构实验教案信息Word文档格式.docx_第18页
第18页 / 共35页
数据结构实验教案信息Word文档格式.docx_第19页
第19页 / 共35页
数据结构实验教案信息Word文档格式.docx_第20页
第20页 / 共35页
亲,该文档总共35页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数据结构实验教案信息Word文档格式.docx

《数据结构实验教案信息Word文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构实验教案信息Word文档格式.docx(35页珍藏版)》请在冰点文库上搜索。

数据结构实验教案信息Word文档格式.docx

{

if(slinsert(&

mylist,i,i+1)==0)

printf("

wrong!

\n"

);

return;

}

if(slget(mylist,i,&

x)==0)

elseprintf("

%d"

x);

slinitiate(seqlist*L1)

L1->

size=0;

intslinsert(seqlist*L2,inti,datatypex)

intj;

if(L2->

size>

=maxsize)

thelistisfull,can'

tbeinserted!

return0;

elseif(i<

0||i>

L2->

size)

theparameterisillegal!

else

for(j=L2->

size;

j>

i;

j--)L2->

list[j]=L2->

list[i];

L2->

list[i]=x;

size++;

return1;

}

intslget(seqlistL3,inti,datatype*x)

if(i<

L3.size-1)

theparameteriisillegal!

*x=L3.list[i];

_

四、实验结果:

12345678910

五、程序各部分功能及实验结果分析:

实验2:

不带头结点单链表的基本操作

1.会定义单链表的结点类型;

2.熟悉对单链表的一些基本操作和具体的函数定义;

3.了解和掌握单链表的调用格式。

1.认真阅读和掌握实验内容所给的程序,并上机运行;

2.保存程序运行结果,并结合程序进行分析;

3.尝试自己调试修改程序并试运行。

三、实验内容:

编写算法实现不带头结点单链表的初始化操作、插入操作和删除操作。

四、实验程序:

alloc.h>

stdlib.h>

typedefstructnode

datatypedata;

structnode*next;

}nslnode;

voidnsllinitiate(nslnode**head);

intnsllinsert(nslnode**head,inti,datatypex);

intnslldelete(nslnode**head,inti,datatype*x);

voidmain(void)

datatypetest[6]={64,6,7,89,12,24};

nslnode*head,*p;

intn=6,i,*x;

nsllinitiate(&

head);

for(i=1;

=n;

nsllinsert(&

head,i,test[i-1]);

for(i=n;

i>

=1;

i--)

nslldelete(&

head,i,x);

printf(“%d”,*x);

voidnsllinitiate(nslnode**head)

*head=NULL;

intnsllinsert(nslnode**head,inti,datatypex)

nslnode*p,*q;

p=*head;

j=1;

while(p!

=NULL&

&

j<

i-1)

p=p->

next;

j++;

if(j!

=i-1&

i!

=1)

printf(“插入位置参数错!

”);

return0;

if((q=(nslnode*)malloc(sizeof(nslnode)))==NULL)exit

(1);

q->

data=x;

if(I==1)

q->

next=*head;

*head=q;

else

next=p->

p->

next=q;

return1;

intnslldelete(nslnode**head,inti,datatype*x)

nslnode*p,*q;

intj;

p=*head;

next!

j++

printf(“删除位置参数错!

if(i==1)

q=p;

head=(*head)->

q=p->

p->

next->

*x=q->

data;

free(q);

五、运行结果:

2412897664

六、程序各部分功能及实验结果分析:

实验3:

带头结点单链表中数据就地逆置

编写算法实现带头结点单链表的就地逆置,即利用原带头结点单链表的结点空间把数据元素序列逆置。

malloc.h>

typedefstructsnode

datatypedata;

structsnode*next;

}slnode;

sllinitiate(slnode**head);

intsllinsert(slnode*head,inti,datatypex);

intslldelete(slnode*head,inti,datatypex);

intsllget(slnode*head,inti,datatype*x);

intsllnotempty(slnode*head);

linlistsurt(slnode*head);

linlistinsert(slnode*head,datatypex);

converse(slnode*head);

main(void)

slnode*head,*p;

intn=6,i;

sllinitiate(&

for(i=1;

sllinsert(head,i,test[i-1]);

linlistsort(head);

linlistinsert(head,25);

converse(head);

p=head->

while(p!

=NULL)

p->

data);

sllinitiate(slnode**head)

if((*head=(slnode*)malloc(sizeof(slnode)))==NULL)exit

(1);

(*head)->

next=NULL;

intsllinsert(slnode*head,inti,datatypex)

slnode*p,*q;

p=head;

j=0;

p=p->

=i-1)

printf("

theinsert-positionparameteriswrong!

if((q=(slnode*)malloc(sizeof(slnode)))==NULL)exit

(1);

intslldelete(slnode*head,inti,datatypex)

while(p->

thedelete-positionparameteriswrong!

q=p->

x=q->

intsllget(slnode*head,inti,datatype*x)

slnode*p;

i)

=i)

theget-positionparameteriswrong!

*x=p->

intsllnotempty(slnode*head)

if(head->

next==NULL)return0;

elsereturn1;

linlistsort(slnode*head)

slnode*curr,*pre,*p,*q;

p=head->

head->

curr=head->

pre=head;

while(curr!

curr->

data<

=p->

data)

pre=curr;

curr=curr->

next=pre->

pre->

linlistinsert(slnode*head,datatypex)

slnode*curr,*pre,*q;

=x)

if((q=(slnode*)malloc(sizeof(slnode)))==NULL)exit

(1);

converse(slnode*head)

next=head->

head->

五、实验结果:

896425241276

实验4:

顺序堆栈的基本操作

1.会定义顺序堆栈抽象数据类型;

2.熟悉顺序堆栈的基本结构;

3.熟悉对顺序堆栈的一些基本操作和具体的函数定义;

4.能按照你对顺序堆栈操作的需要,重新改写主函数并运行。

打印依次出栈的数据元素序列

#definemaxstacksize100

datatypestack[maxstacksize];

inttop;

}seqstack;

voidstackinitiate(seqstack*s);

intstacknotempty(seqstacks);

intstackpush(seqstack*s,datatypex);

intstackpop(seqstack*s,datatype*d);

intstacktop(seqstacks,datatype*d);

seqstackmystack;

stackinitiate(&

mystack);

if(stackpush(&

mystack,i+1)==0)

if(stacktop(mystack,&

todaythedataofthestacktopis:

%d\n"

thepopdataonebyoneis:

while(stacknotempty(mystack))

stackpop(&

mystack,&

x);

%d"

voidstackinitiate(seqstack*s)

s->

top=0;

intstacknotempty(seqstacks)

if(s.top<

=0)return0;

elsereturn1;

intstackpush(seqstack*s,datatypex)

if(s->

top>

=maxstacksize)

stackisfull,can'

tinsert!

stack[s->

top]=x;

top++;

intstackpop(seqstack*s,datatype*d)

top<

=0)

stackisempty!

top--;

*d=s->

top];

intstacktop(seqstacks,datatype*d)

*d=s.stack[s.top-1];

五、程序运行结果:

10987654321

实验5:

判断一个字符序列是否是回文

1.会定义顺序堆栈和顺序循环队列的抽象数据类型;

2.熟悉顺序堆栈和顺序循环队列的基本结构,掌握程序中的用户头文件、实现文件和主文件之间的相互关系及各自的作用;

3.熟悉对顺序堆栈和顺序循环队列的一些基本操作和具体的函数定义;

4.能按照你对顺序堆栈和顺序循环队列操作的需要,重新改写主函数并运行。

编程序判断一个字符序列是否是回文。

要求程序从键盘输入一个字符串,字符串长度小于等于80,用于判断回文的字符串中不包括字符串的结束标记符。

利用顺序堆栈和顺序循环队列,判断一个输入的字符序列是否是回文

string.h>

#definemaxsize80

typedefchardatatype;

inttop;

intfront;

intcount;

}seqcqueue;

voidscqinitiate(seqcqueue*q);

intscqappend(seqcqueue*q,datatypex);

intscqdelete(seqcqueue*q,datatype*d);

intscqgettop(seqcqueueq,datatype*d);

intscqnotempty(seqcqueueq);

voidssinitiate(seqstack*s);

intsspush(seqstack*s,datatypex);

intsspop(seqstack*s,datatype*d);

intssgettop(seqstacks,datatype*d);

intssnotempty(seqstacks);

voidpalindrome(charstr[],intn)

seqcqueuemyqueue;

charx,y;

inti;

ssinitiate(&

scqinitiate(&

myqueue);

n;

scqappend(&

myqueue,str[i]);

sspush(&

mystack,str[i]);

while(scqnotempty(myqueue)==1&

ssnotempty(mystack)==1)

scqdelete(&

myqueue,&

sspop(&

y);

if(x!

=y)

bushihuiwen!

"

shihuiwen!

voidenterstr(charstr[],int*n)

qingcharuzifuchuan(buchaoguo80zifu):

scanf("

%s"

str);

*n=strlen(str);

charch,str[80];

intn;

while

(1)

enterstr(str,&

n);

palindrome(str,n);

\ngoon?

(y/n):

&

ch);

if(ch=='

Y'

||ch=='

y'

)continue;

elsereturn;

voidscqinitiate(seqcqueue*q)

front=0;

count=0;

intscqappend(seqcqueue*q,datatypex)

intrear;

if(q->

count==maxsize)

队列已满无?

!

rear=q->

front+q->

count;

list[rear]=x;

count++;

intscqdelete(seqcqueue*q,datatype*d)

count==0)

循环队列已空!

*d=q->

list[q->

front];

front=(q->

front+1)%maxsize;

count--;

intscqgettop(seqcqueueq,datatype*d)

if(q.count==0)

*d=q.list[q.front];

intscqnotempty(seqcqueueq)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2