博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
队列的基本操作
阅读量:4133 次
发布时间:2019-05-25

本文共 1327 字,大约阅读时间需要 4 分钟。

#include "stdafx.h"#include
using namespace std;typedef struct node{ char data; struct node *link;//指向后缀结点的指针};typedef struct Queue{ node *first,*rear;//定义队列的头和尾指针};Queue * InsertQueue(Queue *Q,char value){ node*newNode=(node*)malloc(sizeof(node)); newNode->data=value; newNode->link=NULL; if(Q->first==NULL) Q->first=Q->rear=newNode; else { Q->rear->link=newNode; Q->rear=newNode; } return Q;}Queue * DeleteQueue(Queue *Q){ node*ptemp; if(Q->first==NULL) cout<<"队列已空!"<
first; if(Q->first==Q->rear) { Q->first=NULL; Q->rear=NULL; } else Q->first=Q->first->link; free(ptemp); } return Q;}Queue * InitQueue(){ char ch; node*newNode; Queue *QL=(Queue*)malloc(sizeof(Queue));//初始化队列 QL->first=(node*)malloc(sizeof(node));//队列中的第一个元素,头尾指针均指向该结点 QL->first->link=NULL; QL->rear=QL->first; cout<<"请输入字符串并回车,初始化队列如下:"<
data=ch; newNode->link=NULL; if(QL->first==NULL) QL->first=QL->rear=newNode; else { QL->rear->link=newNode; QL->rear=newNode; } ch=getchar(); } return QL; }int length(Queue *Q){ int count=0; node*ptemp=Q->first; while(ptemp->link!=NULL) { count++; ptemp=ptemp->link; } return count;}void DisplayQueue(Queue *QL){ node*ptemp; ptemp=QL->first->link; if(ptemp==NULL) cout<<"队列已空!"<
data; ptemp=ptemp->link; if(ptemp!=NULL) cout<<"——> "; } cout<

转载地址:http://zdsvi.baihongyu.com/

你可能感兴趣的文章
JavaSE_day14 集合中的Map集合_键值映射关系
查看>>
异常 Java学习Day_15
查看>>
Mysql初始化的命令
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
软件(项目)的分层
查看>>
菜单树
查看>>
Servlet的生命周期
查看>>
JAVA八大经典书籍,你看过几本?
查看>>
《读书笔记》—–书单推荐
查看>>
JAVA数据类型
查看>>
【Python】学习笔记——-6.2、使用第三方模块
查看>>
【Python】学习笔记——-7.0、面向对象编程
查看>>
【Python】学习笔记——-7.2、访问限制
查看>>
【Python】学习笔记——-7.3、继承和多态
查看>>
【Python】学习笔记——-7.5、实例属性和类属性
查看>>