数据结构实验报告(共10页).doc





《数据结构实验报告(共10页).doc》由会员分享,可在线阅读,更多相关《数据结构实验报告(共10页).doc(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上数据结构实验报告第四次实验学号: 姓名:叶佳伟一、实验目的1、复习线性表、栈、队列的逻辑结构、存储结构及基本操作;2、掌握顺序表、(带头结点)单链表、顺序栈、链队列;3、了解有顺表、链栈、循环队列。3、了解有顺表、链栈、循环队列。二、实验内容1、(必做题)假设有序表中数据元素类型是整型,请采用顺序表或(带头结点)单链表实现:( 1) OrderInsert(&L, e, int (*compare)(a, b)/根据有序判定函数compare,在有序表L的适当位置插入元素e;( 2) OrderInput(&L, int (*compare)(a, b)/根据有序判定
2、函数compare,并利用有序插入函数OrderInsert,构造有序表L;( 3) OrderMerge(&La, &Lb, &Lc, int (*compare)()/根据有序判定函数compare,将两个有序表La和Lb归并为一个有序表Lc。2、(必做题)假设栈中数据元素类型是字符型,请采用顺序栈实现栈的以下基本操作:( 1) Status InitStack (&S) /构造空栈S;( 2) Status Push(&S, e) /元素e入栈S;( 3) Status Pop(&S, &e) /栈S出栈,元素为e。3、(必做题)假设队列中数据元素类型是字符型,请采用链队列实现队列的以下
3、基本操作:( 1) Status InitQueue(&Q) /构造空队列Q;( 2) Status EnQueue(&Q, e) /元素e入队列Q;( 3) Status DeQueue (&Q, &e) /队列Q出队列,元素为e。三、算法描述(采用自然语言描述)分别插入第一个链表和第二个链表的数据; 根据有序判定函数compare,将两个有序表La和Lb归并为个有序表。 输出归并后的有序表。2. 构造一个栈的结构体利用函数initstack构造空栈Push函数将元素依次存储到栈里利用pop函数输出栈顶元素3. 构造Queueptr的结构体 构造一个队列的结构体 利用函数InitQueue构
4、造空队列 EnQueue函数将元素依次存储到栈里 利用DeQueue函数输出栈顶元素四、详细设计(画出程序流程图)五、程序代码(给出必要注释)第一题:#include #include typedef struct LNode int date; struct LNode *next; LNode,*Link; typedef struct LinkList Link head; int len; LinkList; int compare (LinkList *L,int e) int Lc=0; Link p; p=L-head; p=p-next; while(p!=NULL) if(e
5、p-date) p=p-next; Lc+; else return Lc; return Lc; void OrderInsert (LinkList *L,int e,int (*compare)() Link temp,p,q; int Lc,i; temp=(Link)malloc(sizeof(LNode); temp-date=e; p=q=L-head; p=p-next; Lc=(*compare)(L,e); if(Lc=L-len) while(q-next!=NULL) q=q-next; q-next=temp; temp-next=NULL; else for(i=0
6、; inext;q=q-next; q-next=temp;temp-next=p; +L-len; void OrderMerge (LinkList *La,LinkList *Lb,int (*compare)() int i,Lc=0; Link temp,p,q; q=La-head-next; while(q!=NULL) p=Lb-head; temp=(Link)malloc(sizeof(LNode); temp-date=q-date; Lc=(*compare)(Lb,q-date); if(Lc=Lb-len) while(p-next!=NULL) p=p-next;
7、 p-next=temp; temp-next=NULL; else for(i=0; inext; temp-next=p-next; p-next=temp; q=q-next; +Lb-len; LinkList *Initialize (LinkList *NewList) int i; Link temp; NewList=(LinkList *)malloc(2+1)*sizeof(LinkList); for(i=0; idate=0; temp-next=NULL; (NewList+i)-head=temp; (NewList+i)-len=0; return NewList
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 实验 报告 10

限制150内