数据结构大作业封面模板.docx

上传人:b****5 文档编号:26412704 上传时间:2023-06-19 格式:DOCX 页数:23 大小:115.10KB
下载 相关 举报
数据结构大作业封面模板.docx_第1页
第1页 / 共23页
数据结构大作业封面模板.docx_第2页
第2页 / 共23页
数据结构大作业封面模板.docx_第3页
第3页 / 共23页
数据结构大作业封面模板.docx_第4页
第4页 / 共23页
数据结构大作业封面模板.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

数据结构大作业封面模板.docx

《数据结构大作业封面模板.docx》由会员分享,可在线阅读,更多相关《数据结构大作业封面模板.docx(23页珍藏版)》请在冰豆网上搜索。

数据结构大作业封面模板.docx

数据结构大作业封面模板

12级

软件设计大作业

 

题目概念图

难度系数0.7

成绩

班级011213

完成者1学号01121345姓名杨英杰

完成者2学号01121278姓名曹伟

完成者3学号01121289姓名赵汉卿

 

完成日期2014.6.22

(若是多人合作,填写下面的内容,给出所有合作者的信息)

姓名:

杨英杰

主要完成的工作:

线性表、栈和队列、数组和串

 

姓名:

曹伟

主要完成的工作:

图、索引、散列

 

姓名:

赵汉卿

主要完成的工作:

树、绪论、算法设计与分析

 

一、软件系统名称

完整线性表输出。

二、软件分析与设计

1、问题分析:

线性表内容包含两部分,分别是字母(表示下个链表)和数字。

因此链表中节点需要包含指向下一个节点或下个链表的指针等多个数据类型。

系统输入:

线性表名称(字母)和线性表内容(数字)。

系统输出:

线性表(包括线性表名称和线性表内容)。

总功能:

可在原有链表基础上不断添加数字或新链表,并显示每个链表的内容及整体链表的内容。

2、测试样例

在程序输入均含有提示,如果输入错误,会导致重新输入,不会直接退出程序。

输入包含:

输入提示

测试样例

预期结果

请输入需要添加的链表名称(输入END结束)

END

退出

C(已在线性表中的链表字母)

显示下个输入

Sg或D或12(任何不是线性表字母的输入)

输入有误,请重新输入

请输入数字或新链表名称(输入end结束)

end

退出

132(数字)或Q(未保存在线性表中的链表字母)

显示下个输入

Ass或46s(不正常输入)

输入有误,请重新输入

3、全局变量包括:

所有链表的指针和表示链表指针数目的数字变量;用语构成队列的数组指针和表示表示队列的两个变量front和rear。

4、模块分类

创建链表模块

函数名称:

CreateList

函数参数:

链表名称name

函数功能:

生成链表

返回值:

链表头指针

伪代码描述:

定义头指针;

分配节点空间;

节点数据初始化(链表名=name);

返回头指针

初始化模块

函数名称:

InitList

函数参数:

函数功能:

链表初始化

返回值:

伪代码描述:

在链表中原有链表中插入数字和链表;

新链表的插入数字和链表;

插入链表模块

函数名称:

AtLast

函数参数:

链表头指针

函数功能:

寻找链表中最后指针

返回值:

最后指针

伪代码描述:

While(下一个节点指针不空)

指向下一个节点指针

返回

函数名称:

InsertNumber

函数参数:

链表头指针,数字

函数功能:

链表中插入数字

返回值:

新节点指针

伪代码描述:

寻找最后指针;

分配节点空间;

节点数据初始化;

链表与节点链接

返回节点指针

函数名称:

InsertList

函数参数:

链表头指针,要插入链表头指针

函数功能:

链表中插入指针

返回值:

新链表头指针

伪代码描述:

寻找最后指针;

分配节点空间;

节点数据初始化

原链表与节点连接

节点与要插入链表头指针链接

返回节点指针

数组队列模块

函数名称:

Qinit

函数参数:

函数功能:

队列初始化

返回值:

伪代码描述:

front=rear=0

函数名称:

push

函数参数:

指针

函数功能:

入队列

返回值:

伪代码描述:

指针进入数组

front++

函数名称:

pop

函数参数:

函数功能:

出队列

返回值:

伪代码描述:

rear++

函数名称:

top

函数参数:

指针

函数功能:

返回队列头指针

返回值:

队列头指针

伪代码描述:

返回队列头指针

函数名称:

empty

函数参数:

函数功能:

判断队列是否空

返回值:

bool变量

伪代码描述:

队列空;返回true;

Else返回false

删除模块

函数名称:

DeleteList

函数参数:

链表头指针

函数功能:

释放线性表空间

返回值:

伪代码描述:

队列初始化;

头指针入队列

While(队列不空)

出队列并存储队首值

指向下一个节点

If(节点为数字)

释放空间、

else

指针入队列并释放空间

显示模块

函数名称:

Show

函数参数:

函数功能:

输出只有数值的完整线性表

返回值:

伪代码描述:

显示线性表字母

输出函数

换行

函数名称:

ShowL

函数参数:

指针

函数功能:

输出链表内容

返回值:

伪代码描述:

指向下一个节点

If(节点为数字)

输出数字

else

递归调用函数,传递此节点指针

函数名称:

ShowList

函数参数:

指针

函数功能:

输出线性表内容

返回值:

伪代码描述:

队列初始化;

头指针入队列

While(队列不空)

出队列并存储队首值

显示链表头字母

指向下一个节点

If(节点为链表节点)

显示链表头字母和‘,’

入队列

else

显示数字和‘,’

输入模块

函数名称:

NoCreate

函数参数:

链表名称name

函数功能:

判断队列是否存在于线性表

返回值:

bool量

伪代码描述:

数组中依次寻找

If找到false

无返回true

函数名称:

Input

函数参数:

函数功能:

输入处理

返回值:

伪代码描述:

ShowList

输出提示

输入(为字符串)

While(输入不结束)

{

If(输入合理(为单一字母且已存在线性表))

{

找到线性表中的该链表

输出提示

输入(为字符串)

While(输入不结束)

{

If(输入为新单一字母)

新建链表并插入,并存储如全局数组中

Elseif(为数字)

字符串转化为数字并加入原链表中

Else

提示输入错误

提示并重新输入

}

}

Else

提示输入错误

提示并重新输入

}

5、流程图

三、运行环境

codeblocks(建议编译器为gcc)。

四、软件使用说明

软件系统输入以输出和异常处理均在上述表格中得到。

五、源代码

#include

#include

#include

#include

usingnamespacestd;

typedefstructnode

{

boolisList;

intnumber;

node*nextNumber,*nextList;

charlistName;

}List;

typedefstructnodeh

{

charname;

List*head;

}HList;

HListListHead[100];

intNlisthead=0;

List*CreateList(charname);

List*AtLast(List*head);

List*InsertNumber(List*head,intnumber);

List*InsertList(List*head1,List*head2);

voidInitList(List*head);

voidShowList(List*head);

voidDeleteList(List*head);

voidInput();

boolNoCreate(charname);

voidShow();

intmain()

{

List*head=CreateList('A');

InitList(head);

Input();

Show();

DeleteList(head);

return0;

}

List*CreateList(charname)

{

List*head;

head=(List*)malloc(sizeof(List));

head->listName=name;

head->isList=true;

head->nextNumber=head->nextList=NULL;

returnhead;

}

List*AtLast(List*head)

{

while(head->nextNumber)

head=head->nextNumber;

returnhead;

}

List*InsertNumber(List*head,intnumber)

{

head=AtLast(head);

List*newNode=(List*)malloc(sizeof(List));

newNode->isList=false;

newNode->number=number;

newNode->nextList=newNode->nextNumber=NULL;

head->nextNumber=newNode;

returnnewNode;

}

List*InsertList(List*head1,List*head2)

{

head1=AtLast(head1);

List*newNode=(List*)malloc(sizeof(List));

newNode->isList=true;

newNode->listName=head2->listName;

newNode->nextNumber=NULL;

newNode->nextList=head2;

head1->nextNumber=newNode;

returnhead2;

}

voidInitList(List*head)

{

//A链表初始化

InsertNumber(head,1);

InsertNumber(head,2);

InsertNumber(head,3);

InsertNumber(head,4);

InsertNumber(head,5);

List*head1=CreateList('B');

InsertList(head,head1);

//B链表初始化

InsertNumber(head1,7);

InsertNumber(head1,8);

InsertNumber(head1,9);

List*head2=CreateList('C');

InsertList(head1,head2);

//C链表初始化

InsertNumber(head2,10);

//存储所有链表头指针

ListHead[0].head=head;

ListHead[1].head=head1;

ListHead[2].head=head2;

ListHead[0].name='A';

ListHead[1].name='B';

ListHead[2].name='C';

Nlisthead=3;

}

//队列定义及所有操作

constintMAXQ=10000;

List*ListQueue[MAXQ];

intfront,rear;

//初始化(队列清空)

voidQinit()

{

front=rear=0;

}

//入队列

voidpush(List*head)

{

if(front

ListQueue[front++]=head;

}

//出队列

voidpop()

{

rear++;

}

//返回队首元素

List*top()

{

if(rear

returnListQueue[rear];

returnNULL;

}

//判断队列是否为空

boolempty()

{

if(front==rear)

returntrue;

returnfalse;

}

//以上为队列所有操作

voidShowList(List*head)

{

Qinit();

push(head);

while(!

empty())

{

List*temp=top();

pop();

printf("%c->",temp->listName);

temp=temp->nextNumber;

while(temp)

{

if(temp->isList)

{

printf("%c",temp->listName);

push(temp->nextList);

if(temp->nextNumber)

{

printf(",");

}

}

else

{

printf("%d",temp->number);

if(temp->nextNumber)

printf(",");

}

temp=temp->nextNumber;

}

printf("\n");

}

}

//判断一个链表名称是否已被创建

boolNoCreate(charname)

{

for(inti=0;i

if(ListHead[i].name==name)

returnfalse;

returntrue;

}

voidInput()

{

ShowList(ListHead[0].head);

chartemp1[20]="",temp2[20]="";

boolflag=true;

puts("请输入需要添加的链表名称(输入END结束)");

scanf("%s",temp1);

while(strcmp(temp1,"END"))

{

flag=true;

if(temp1[0]>='A'&&temp1[0]<='Z'&&!

temp1[1])

{

for(inti=0;i

if(temp1[0]==ListHead[i].name)

{

flag=false;

puts("请输入数字或新链表名称(输入end结束)");

scanf("%s",temp2);

while(strcmp(temp2,"end"))

{

boolinputok=true;

if(temp2[0]>='A'&&temp2[0]<='Z'&&!

temp2[1]&&NoCreate(temp2[0]))

{

List*headi=CreateList(temp2[0]);

InsertList(ListHead[i].head,headi);

ListHead[Nlisthead].head=headi;

ListHead[Nlisthead++].name=temp2[0];

}

else

{

intnumber=0;

for(intj=0;temp2[j];j++)

if(temp2[j]>='0'&&temp2[j]<='9')

number=number*10+temp2[j]-'0';

else

{

inputok=false;break;

}

if(inputok)

InsertNumber(ListHead[i].head,number);

}

if(!

inputok)

puts("输入有误,请重新输入");

puts("请输入数字或新链表名称(输入end结束)");

scanf("%s",temp2);

}

}

}

if(flag)

puts("输入有误,请重新输入");

else

ShowList(ListHead[0].head);

puts("请输入需要添加的链表名称(输入END结束)");

scanf("%s",temp1);

}

}

voidDeleteList(List*head)

{

Qinit();

push(head);

while(!

empty())

{

List*temp1=top(),*temp2;

pop();

temp1=temp1->nextNumber;

while(temp1)

{

if(temp1->isList)

push(temp1->nextList);

temp2=temp1->nextNumber;

free(temp1);

temp1=temp2;

}

}

}

voidShowL(List*head)

{

List*temp=head->nextNumber;

while(temp)

{

if(temp->isList)

ShowL(temp->nextList);

else

printf("%d",temp->number);

temp=temp->nextNumber;

}

}

voidShow()

{

List*head=ListHead[0].head;

printf("%c->",ListHead[0].name);

ShowL(head);

puts("");

}

六、测试

七、对算法的时间效率进行分析

在程序中,队列操作时间复杂度均为O

(1),而线性表的基本操作:

删除,显示,检查,查找链表的时间复杂度均为O(n)。

八、收获、体会、对课程的意见或建议。

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

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1