数据结构实验报告文档格式.docx

上传人:b****1 文档编号:1474688 上传时间:2023-04-30 格式:DOCX 页数:14 大小:63.79KB
下载 相关 举报
数据结构实验报告文档格式.docx_第1页
第1页 / 共14页
数据结构实验报告文档格式.docx_第2页
第2页 / 共14页
数据结构实验报告文档格式.docx_第3页
第3页 / 共14页
数据结构实验报告文档格式.docx_第4页
第4页 / 共14页
数据结构实验报告文档格式.docx_第5页
第5页 / 共14页
数据结构实验报告文档格式.docx_第6页
第6页 / 共14页
数据结构实验报告文档格式.docx_第7页
第7页 / 共14页
数据结构实验报告文档格式.docx_第8页
第8页 / 共14页
数据结构实验报告文档格式.docx_第9页
第9页 / 共14页
数据结构实验报告文档格式.docx_第10页
第10页 / 共14页
数据结构实验报告文档格式.docx_第11页
第11页 / 共14页
数据结构实验报告文档格式.docx_第12页
第12页 / 共14页
数据结构实验报告文档格式.docx_第13页
第13页 / 共14页
数据结构实验报告文档格式.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数据结构实验报告文档格式.docx

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

数据结构实验报告文档格式.docx

e)//队列Q出队列,

元素为e。

三、算法描述

(采用自然语言描述)

⒈⑴分别插入第一个链表和第二个链表的数据;

⑵根据有序判定函数compare,将两个有序表La和Lb归并为个有序表。

⑶输出归并后的有序表。

2.

⑴构造一个栈的结构体

⑵利用函数initstack构造空栈

⑶Push函数将元素依次存储到栈里

⑷利用pop函数输出栈顶元素

3.

1构造Queueptr的结构体

2构造一个队列的结构体

3利用函数InitQueue构造空队列

4EnQueue函数将元素依次存储到栈里

5利用DeQueue函数输出栈顶元素

四、详细设计

(画出程序流程图)

五、程序代码

(给出必要注释)

第一题:

#include<

stdio.h>

stdlib.h>

typedefstructLNode

{intdate;

structLNode*next;

}LNode,*Link;

typedefstructLinkList

{Linkhead;

intlen;

}LinkList;

intcompare(LinkList*L,inte)

{intLc=0;

Linkp;

p=L->

head;

p=p->

next;

while(p!

=NULL)

{if(e>

p->

date)

{p=p->

Lc++;

}

else

returnLc;

voidOrderInsert(LinkList*L,inte,int(*compare)())

{Linktemp,p,q;

intLc,i;

temp=(Link)malloc(sizeof(LNode));

temp->

date=e;

p=q=L->

Lc=(*compare)(L,e);

if(Lc==L->

len)

{while(q->

next!

{q=q->

q->

next=temp;

next=NULL;

{for(i=0;

i<

Lc;

i++)

q=q->

next=p;

++L->

len;

voidOrderMerge(LinkList*La,LinkList*Lb,int(*compare)())

{inti,Lc=0;

Linktemp,p,q;

q=La->

head->

while(q!

{p=Lb->

date=q->

date;

Lc=(*compare)(Lb,q->

date);

if(Lc==Lb->

{while(p->

next=p->

++Lb->

LinkList*Initialize(LinkList*NewList)

{inti;

Linktemp;

NewList=(LinkList*)malloc((2+1)*sizeof(LinkList));

for(i=0;

2+1;

{temp=(Link)malloc(sizeof(LNode));

date=0;

(NewList+i)->

head=temp;

len=0;

returnNewList;

voidInsert(LinkList*NewList)

{inta,i;

charc;

printf("

在第1个表中插入数据,以空格和回车为间隔,输入”.”对下个表插入数据\n"

);

2;

{while

(1)

{scanf("

%d"

&

a);

c=getchar();

if(c=='

.'

{if(i<

2-2)

在第%d个表中插入数据,以空格和回车为间隔,输入”.”对下个表插入数据\n"

i+2);

elseif(i==2-2)

在第%d个表中插入数据,以空格和回车为间隔,输入”.”结束输出\n"

break;

{OrderInsert((NewList+i),a,compare);

voidShow(LinkList*L)

{Linkp;

p=L->

{printf("

%d\t"

p->

voidDisplay(LinkList*NewList,void(*Show)())

所有有序表如下\n"

第一个有序表为:

\n"

(*Show)(NewList+0);

第二个有序表为:

(*Show)(NewList+1);

归并后有序表为\n"

(*Show)(NewList+2);

intmain()

{LinkList*NewList=NULL;

inti;

\t开始插入数据\n"

NewList=Initialize(NewList);

Insert(NewList);

{OrderMerge(NewList+i,NewList+2,compare);

Display(NewList,Show);

return0;

第二题:

malloc.h>

#defineM50

typedefstruct//定义一个栈结构

{

inttop;

intarray[M];

}Stack;

voidInit(Stack*s);

//初始化栈的函数

voidPush(Stack*s,intdata);

//进行压栈操作的函数

voidTraverse(Stack*s);

//遍历栈函数

charPop(Stack*s);

//进行出栈操作的栈函数

voidClear(Stack*s);

//清空栈的函数

intmain()

Stacks;

//定义一个栈

inti;

intnum;

chardata;

//临时保存用户输入的数据

charre_num;

//保存pop函数的返回值

Init(&

s);

printf("

你想输入几个数据:

"

scanf("

num);

for(i=0;

i<

num;

i++)

{

第%d个字符:

i+1);

%s"

data);

Push(&

s,data);

}

Traverse(&

//调用遍历函数

你想去掉几个字符:

"

你去掉的字符是:

re_num=Pop(&

//调用Pop函数,并把返回至赋给re.num

%c"

re_num);

看看删除后还有啥:

Clear(&

//调用清空栈函数

遍历下看看栈空没\n"

return0;

}

voidInit(Stack*s)//进行栈的初始化函数

s->

top=-1;

voidPush(Stack*s,intdata)/*进栈*/

if(s->

top>

=M-1)return;

/*full*/

top++;

array[s->

top]=data;

voidTraverse(Stack*s)//遍历栈的函数

for(i=0;

=s->

top;

%2c"

s->

array[i]);

charPop(Stack*s)//进行出栈操作函数

charx;

x=s->

top];

top--;

returnx;

voidClear(Stack*s)//清空栈的函数

s->

第三题:

#include<

typedefvoidStatus;

typedefintQElemType;

#defineSTACK_INIT_SIZE10//初始容量

#defineSTACKINCREMENT5//容量增量

typedefstructQNode{

QElemTypedata;

structQNode*next;

}QNode,*QueuePtr;

typedefstruct{

QueuePtrfront;

//队头指针

QueuePtrrear;

//队尾指针

}LinkQueue;

 

StatusInitQueue(LinkQueue&

Q){

//构造一个空对列Q

Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode));

if(!

Q.front)exit(-1);

Q.front->

StatusEnQueue(LinkQueue&

Q,QElemTypee){

//插入元素e为对列Q的新元素

QueuePtrp;

p=(QueuePtr)malloc(sizeof(QNode));

p)printf("

OVERFLOW"

p->

data=e;

Q.rear->

Q.rear=p;

StatusDeQueue(LinkQueue&

//若对列不空,用e返回其值,并返回OK

//否则返回ERROR

if(Q.front==Q.rear)printf("

ERROR"

p=Q.front->

e=p->

data;

对列中的队头元素为:

%d\n"

e);

if(Q.rear==p)Q.rear=Q.front;

free(p);

main()

{LinkQueueQ;

intn,i;

QElemTypee;

InitQueue(Q);

请输入队列中要入队列的元素个数:

n);

n;

{printf("

队列里的第%d个元素为:

e);

EnQueue(Q,e);

DeQueue(Q,e);

六、测试和结果

(给出测试用例以及测试结果)

七、用户手册

(告诉用户如何使用程序)

1.使用MicrosoftVisualC++

2.使用MicrosoftVisualC++

3.使用MicrosoftVisualC++

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

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

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

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