ImageVerifierCode 换一换
格式:DOCX , 页数:100 ,大小:230.47KB ,
资源ID:10390664      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10390664.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(中北大学 算法与数据结构实验报告.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

中北大学 算法与数据结构实验报告.docx

1、中北大学 算法与数据结构实验报告 实验类别:算法与数据结构 专 业:信息与计算科学 班 级:13080241 学 号:1308024120 姓 名:杨燕 中北大学理学院实验一 链表的应用(一)建立线性表【实验内容】1、画出详细规范的算法流程图2、定义链表结点数据类型3、定义链表数据类型4、实现单向线性链表的建立5、实现单向线性链表取元素6、实现单向线性链表遍历7、实现单向线性链表插入8、实现单向线性链表删除【实验方法与步骤】1、定义链表结点数据类型typedef struct LNode int data; struct LNode *next;LNode,*LinkList;其中int da

2、ta;表示节点是整型数据,若定义浮点型的为:float data;其他类似。2、定义链表数据类型typedef char DateTypetypedef struct LNode DateType data; struct LNode *next;LNode,*LinkList;3、实现单向线性链表的建立#include #include #include typedef struct LNode int data; struct LNode *next;LNode,*LinkList;void CreateList_L(LinkList &L,int n) /逆位序输入n个数据元素的值,建立

3、带头结点的单链表L int i; LNode *p; L=(LinkList)malloc(sizeof(LNode); L-next=NULL;/先建立一个带头结点的空链表 cout请输入创建的单链表中的数据: 0;-i) p=(LinkList)malloc(sizeof(LNode);/生成新结点 cinp-data; p-next=L-next;/将新结点插入到单链表的头 L-next=p;/修改单链表头结点的指针域 /for结束 if(n) cout成功创建一个单链表!endl; else cout创建了一个空链表!endl; void main() LinkList L; int

4、InitLNodeNum; coutCreateList_L.cppendl=endl; coutendlInitLNodeNum; CreateList_L(L,InitLNodeNum); coutOK.!endl; getch();/end of main() function4、实现单向线性链表取元素#include #include #include #define ElemType int #define LIST_MAX_LENGTH 100 /LIST_MAX_LENGTH是单链表L的最大长度typedef struct LNode ElemType data; struct

5、LNode *next;LNode,*LinkList;void CreateList_L(LinkList &L,int n) /创建一个带头结点的单链表L int i; LNode *p; L=(LinkList)malloc(sizeof(LNode); L-next=NULL; for(i=n;i0;-i) p=(LinkList)malloc(sizeof(LNode); cinp-data; p-next=L-next; L-next=p; int GetElem_L(LinkList L,int i,int &e) /GetElem_L() function/L为带头结点的单链表

6、的头指针,当第i个元素存在时,其值赋给e并返回OK, /否则返回Error LNode *p; int j=1; p=L-next; /初始化,p指向链表第一个结点,j为计数器 while(p&jnext;+j; if(!p|ji) cout这个元素 i 不存在!data; return (e); /结束单链表的取元素void main() /main() function LinkList L; int e; /e can be Every DataType int i,LListNodeNum; /j is a counter for cycle coutGetElem_L.cppendl

7、=endlendl; coutLListNodeNum; cout请输入创建的单链表中的数据: endl; CreateList_L(L,LListNodeNum); coutendl成功创建一个单链表L!endl; cout你想提取哪一个位置上的数据?: i; /输入要提取的数据 if(iLListNodeNum) coutendl输入错误!endl; GetElem_L(L,LListNodeNum-i+1,e); coutendl位置i 在单链表中的数据是: e; coutendl.OK.!endl; getch();5、实现单向线性链表遍历#include #include #incl

8、ude #include #define LIST_INIT_LENGTH 10 /LIST_INIT_LENGTH is the Init_Define_Length of LinkList typedef int ElemType; typedef struct LNode int data; struct LNode *next; LNode,*LinkList;void CreateList_L(LinkList &L,int n) /CreatList_L() subfunction /To Creatre a LinkList L with HeadNode int i; LNod

9、e *p; int arrayLIST_INIT_LENGTH; L=(LinkList)malloc(sizeof(LNode); L-next=NULL; printf(Please input the nodes data: n); for(i=0;in;i+) /input the data to create the LinkList scanf(%d,&arrayi); for(i=0;idata=arrayi; /for example to a CreateList p-next=L-next; L-next=p; /end of for /end of CreateList_

10、L() function void Contray(LinkList &head) /Contray() function /Delete the NO.i element of LinkList and return by variable e LNode *p,*q; p=head; head=NULL; while(p) q=p; p=p-next; q-next=head; head=q; /end of while coutendlSuccess to Contray the LinkList !;/end of Contray() functionvoid main() /main

11、() function LinkList L; LNode *p; int i,LNodeNum; /j is just a counter for cycle coutContray.cppendl=endlendl; coutHow many nodes do you want to create? ; cinLNodeNum; CreateList_L(L,LNodeNum); p=L; coutendlThe next ones Inserted Direction is always in front of this.endl; for(i=0;inext; coutdata ; /

12、output the LinkList before Contray coutendl; cout-endl; Contray(L); /call function Contray(); coutendlthe LinkList after contray is: ; for(i=0;iLNodeNum;+i) coutdatanext; coutendl.OK.!endl; getch();/end of main() function6、实现单向线性链表插入# include # include # include # include # define INIT_LENGTH 10# de

13、fine OK 1# define ERROR 0typedef struct LNode /define LNode structure int data; struct LNode *next;LNode,*Linklist;int ListInsert_L(Linklist &L,int i,int e) /在带头结点的单链线性表L中第i个位置之前插入元素e LNode *p=L; int j=0; while(p&jnext; +j; if(!p|ji-1) /i小于1或i大于表长 cout错误!这个位置不存在!data=e; s-next=p-next; p-next=s; retu

14、rn (OK); /ListInsert_L() endvoid main() /main() function int i,j,e; LNode node10; LNode *L,*p; int arrayINIT_LENGTH+1=5,8,12,18,25,30,37,46,51,89; L=node; L=(Linklist)malloc(sizeof(LNode); L-next=NULL; for (i=10;i0;i-) p=(Linklist)malloc(sizeof(LNode); p-data=arrayi-1; p-next=L-next; L-next=p; p=L;

15、coutendlendlListInsert_L.cpp; coutendl=; cout endlendl原来的单链线性表L为: ; for(i=0;inext; coutdata ; coutendlendlj; coute; if(ListInsert_L(L,j,e) cout endl新的单链线性表L为: ; p=L; for(i=0;inext; coutdata ; coutendlendl.OK!.; getch();7、实现单向线性链表删除#include #include #include typedef struct LNode int data; struct LNod

16、e *next;LNode,*LinkList;void CreateList_L(LinkList &L,int n) /CreateList_L() function /创建一个带头结点的单链表L int i; LNode *p; L=(LinkList)malloc(sizeof(LNode); L-next=NULL; for(i=0;ip-data; p-next=L-next; L-next=p; /结束for/end of CreateList() functionint ListDelete_L(LinkList &L,int i,int &e) /ListDelete_L()

17、 function /在带头结点的单链线性表L中,删除第i个元素,并由e返回其值 LNode *p,*q; int j=0; p=L; while(p-next&jnext;+j; if(!p|ji-1) /删除位置不合理 cout位置i的数据不存在!next; /用指针q指向被删除的结点 p-next=q-next; /删除第i个结点 e=q-data; /取出第i个结点数据域值 free(q); /释放第i个结点 return (e); /结束删除元素void main() /main() function LinkList L; LNode *p; int e; /e can be Ev

18、ery DataType int i,j; /j is just a counter for cycle int LListNodeNum; coutListDelete_L.cppendl=endlendl; coutLListNodeNum; coutendl请输入创建的单链表中的数据 endl; CreateList_L(L,LListNodeNum); coutendlnext; while(p) /输出创建的单链表 coutdatanext; /end of for coutendlendli; /输入要删除的位置 if(i= LListNodeNum) cout数据i已经被删除Li

19、stDelete_L(L,i,e)endl; for(j=1;jnext; coutdata ; /输出新的单链表 /结束for coutendlendl.OK.!endl; /结束if else coutInput Error!endl; getch();/end of main() function【实验结果】1、写出实验的总结与体会,要简洁、真实、深刻;忌空话、套话2、单向链表和双向链表在实现时的区别3、单向链表如何修改实现循环链表实验二 链表的应用(二)栈的应用【实验内容】1、实现单向链栈的抽象数据类型2、实现单向链栈的建立、销毁、取栈顶元素、压栈、弹栈的运算3、给出包含括号和+、-、

20、*、四则运算的运算符优先级表4、创建运算符栈和运算数栈5、实现有一定通用性的程序,实现一个四则运算表达式的求解6、设计测试用的运算表达式,通过键盘输入进行测试【实验方法与步骤】1、构造空链式队列算法# include # include # include # define MAXQSIZE 100# define OK 1# define ERROR 0typedef int QElemType;typedef struct SqQueue/创建一个头结点 QElemType *base; int front; int rear;SqQueue;int InitQueue(SqQueue &

21、Q) Q.base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType); if(!Q.base)/存储空间分配失败 coutendlOverflow ! ; return (ERROR); Q.front=Q.rear=0; return (OK); /InitQueue() endvoid main() /main function SqQueue Q; coutendlendlInitQueue.cpp; coutendl=; if(InitQueue(Q) coutendlendl成功!链式队列已被构造!; coutendlendl.OK!.;

22、getch(); /main() end2、销毁链式队列算法# include # include # include # define MAXQSIZE 100# define OK 1# define ERROR 0typedef int QElemType;typedef struct QNode /define structure QNode QElemType data; struct QNode *next;QNode,*QueuePtr;typedef struct LinkQueue /define structure LinkQueue QueuePtr front; Que

23、uePtr rear;LinkQueue;int EnQueue(LinkQueue &Q,QElemType e) /构造队列 QNode *p; p=(QueuePtr)malloc(sizeof(QNode); if(!p) coutendldata=e; p-next=NULL; if(Q.front=NULL) /new QNode Q.front=Q.rear=p; return (OK); Q.rear-next=p; Q.rear=p; return (OK); /EnQueue() endint DestroyQueue(LinkQueue &Q) /销毁队列Q while(Q.front) Q.rear=Q.front-next; free(Q.front); Q.front=Q.rear; return (OK); /DestroyQueue() endvoid main() /main() function int i,e=1; LinkQueue Q; QNode *q; Q.front=Q.rear=NULL; coutendlendlDestroyQueue.cpp; coutendl=endlendl; while(e) coute; if(e) EnQueue(Q,e);

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

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