实验九 链队列_第1页
实验九 链队列_第2页
实验九 链队列_第3页
实验九 链队列_第4页
实验九 链队列_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验九链队列1.创建一个包含数字元素的链队列,同时具有如下功能:【1】初始化一个链队列【2】输出链队列中各结点的值【3】判断当前链队列是否为空【4】给出当前的队列头元素【5】在链队列中插入值为x的新元素【6】在链队列中出队列操作并打印被删除的元素提示:第一步:定义该链队列的存储结构(元素都是整型数字)第二步:定义5种操作的函数第三步:编写main函数。使用switch函数,根据用户的输入,实现链队列相应的基本操作。2.选做实验:把第1题中的数字元素改为学生信息表中的信息(学号,姓名,成绩)同时具有上面的5种功能。#include<stdio.h>#include<stdlib.h>typedefstructqnode{intdata;structqnode*next;}linkqlist;typedefstruct{linkqlist*front;linkqlist*rear;}linkqueue;linkqueue*init(){linkqueue*p;linkqlist*s;p=(linkqlist*)malloc(sizeof(linkqlist));s=(linkqlist*)malloc(sizeof(linkqlist));p->front=s;p->rear=p->front;p->front->next=NULL;returnp;}intempty(linkqueue*q){intv;if(q->front==q->rear)v=1;elsev=0;returnv;}intenqueue(linkqueue*q,inte){linkqlist*p;p=(linkqlist*)malloc(sizeof(linkqlist));p->data=e;p->next=NULL;q->rear->next=p;q->rear=p;}voidvisit(linkqueue*p){linkqlist*q;q=p->front->next;printf("displaythelinklist:\n");if(p->front==p->rear)printf("thelinklistisempty!");else{while(q){printf("%d->",q->data);q=q->next;}}printf("\n");}intgethead(linkqueue*q){intv;if(q->front==q->rear)v=-1;elsev=q->front->next->data;returnv;}intdequeue(linkqueue*q){linkqlist*p;inte;if(q->front==q->rear)printf("thelinklistisempty");elsep=(q->front)->next;(q->front)->next=p->next;e=p->data;if(q->rear==p)q->rear=q->front;free(p);returne;}main(linkqueue*head){intn,i,y;intselect;inta,x1,x3,x5,e;printf("createaemptylinkqlist\n");head=init();printf("pleaseinputlinkqlistlength:\n");scanf("%d",&n);for(i=1;i<=n;i++){printf("pleaseinputlinkqlistvalue\n");scanf("%d",&a);enqueue(head,a);printf("select1---visit()\n");printf("select2---empty()\n");printf("select3---gethead()\n");printf("select4---enqueue()\n");printf("select5---dequeue()\n");printf("pleaseselect(1--5):");scanf("%d",&select);switch(select){case1:{visit(head);break;}case2:{x1=empty(head);if(x1==1)printf("thelinkqueueisempty!");elseprintf("thelinkqueueisnotempty");break;}case3:{x3=gethead(head);printf("head->front->%d\n",x3);break;}case4:{printf("pleaseinsertthevalue:");scanf("%

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论