1、SY-023实 验 报 告 课程名称: 数据结构 系部名称: 计算机科学与技术 专业班级: 计科15-2 学生姓名: 刘航征 学 号: 20151544 指导教师: 王姝音 黑龙江工程学院教务处制实验项目实验四:队列的链表储存结构及实现实验日期2016.9.9实验地点A507同组人数1实验台号一、实验目的(1)掌握线性表的定义与实现。二、实验仪器设备 计算机 系统:windows 7;三、实验原理数据结构程序设计基本方法实现步骤:编写、编译、链接、执行四、实验内容或步骤内容:(1)初始化栈(2)入栈和出栈(3)判断栈是否为空(4)编写主函数实现2)实验步骤:1)编写C的源程序如下:#inclu
2、de #include #define ElemType inttypedef struct NodeTypeElemType data;struct NodeType *next;NodeType;typedef struct NodeType *font, *rear;LinkQueue;NodeType *p, *s, *h;void outlin(LinkQueue qq);void creat(LinkQueue *qe);void insert(LinkQueue *qe, ElemType x);ElemType delete(LinkQueue *qe);int main(vo
3、id)LinkQueue que;ElemType y, x;int i, X, Y, cord;doprintf(n主菜单 n);printf( 1建立链表队列n);printf( 2入队一个元素n);printf( 3出队一个元素n);printf( 4结束程序运行n);printf(=n);printf( 请输入您的选择(1, 2, 3, 4): );scanf(%d, &cord);switch(cord)case 1: creat(&que);outlin(que);break;case 2: printf(n x= );scanf(%d, &X);insert(&que, X);o
4、utlin(que);break;case 3: Y=delete(&que);printf(n x=%dn, Y);outlin(que);break;case 4: exit(0);while(cordnext;while(p!=NULL)printf( data=%4dn, p-data);p=p-next;printf(n outend nn);void insert(LinkQueue *qe, int x)s=(NodeType*)malloc(sizeof(NodeType);s-data=x;s-next=NULL;qe-rear-next=s;qe-rear=s;ElemTy
5、pe delete(LinkQueue *qe)ElemType x;if(qe-font=qe-rear)printf(队列为空。 n);x=0;elsep=qe-font-next;qe-font-next=p-next;if(p-next=NULL)qe-rear=qe-font;x=p-data;free(p);return(x);void creat(LinkQueue *qe)int i, n, x;h=(NodeType *)malloc(sizeof(NodeType);h-next=NULL;qe-font=h; /头指针指向NULLqe-rear=h; /尾指针指向NULLprintf(n= );scanf(%d, &n);for(i=0;in;i+)printf(n data= );scanf(%d, &x);insert(qe, x);2)编译3)执行#建立链表队列:#入队一个元素:#出队一个元素:#结束程序:六、数据处理结果(结论)正确七、实验中存在的问题、进一步的想法等八、教师评语成 绩指导教师签字: 年 月 日注:此报告为参考格式,各栏项目可根据实际情况进行调整。