链队列的出队入队
来源:互联网 发布:最好玩的网络手机游戏 编辑:程序博客网 时间:2024/04/30 07:36
#includeusing namespace std;struct Node{ //存放元素的结点类型,数据域和指针域int data;Node *next;};class LinkQueue{private:Node *front,*rear; //头指针和尾指针public:LinkQueue();~LinkQueue();void EnQueue(int e); //入队int DeQueue(); //出队int GetQueue(); //取队头元素int Empty(); //判断链队列是否为空}; //成员函数的类外定义LinkQueue::LinkQueue(){ front=new Node;front->next=NULL;rear=front;}LinkQueue::~LinkQueue(){Node *p;while(front!=NULL){p=front;front=p->next;delete p;}}void LinkQueue::EnQueue(int e){ //新建一个结点,其数据域存放入队元素e,指针域置空Node *P=new Node; //生成新元素结点P->data=e; //装入元素eP->next=NULL;//为队尾结点rear->next=P; //插入新结点rear=P; //修改尾指针}int LinkQueue::DeQueue(){ //把队头结点地址赋给p,头指针front下移,返回p结点的数据元素,if(front==rear) throw"队列为空";//无法删除Node *p=front->next; //定义结点P指向要删除的队头结点front->next=p->next;//删除队头结点int e=p->data;//取出数据域的值if(rear==p) rear=front;free(p);return e;}int LinkQueue::GetQueue()//读取队头元素{if(front==rear) throw"队列为空";return front->next->data;}int LinkQueue::Empty(){if(front==rear) return 1;else return 0;}void main(){try{LinkQueue Q; //对象try{cout<<"执行元素32入队操作,";Q.EnQueue(32);}catch(char *p){cout<
总结:注意数据结构
阅读全文
0 0
- 链队列的入队、出队
- 链队列的出队入队
- 队列的出队/入队的操作
- 链队列的初始化、入队、出队等操作实现
- 链队列的初始化、入队、出队及打印(数据结构)
- 队列的入队、出队操作实现
- 顺序队列的创建、入队、出队
- 队列的创建,入队,出队,遍历
- 队列的入队和出队操作
- 队列的入队和出队
- 队列的入队/出队操作
- 队列的入队、出队操作
- 队列的入队、出队基本操作
- 队列的入队出队操作
- 链式队列的入队出队操作
- 队列之出队入队
- 队列操作--出队入队
- 队列的创建、入队、出队、打印、统计队列长度
- android studio 引入glide4.2报错
- zheng项目-从rpc-service开始!
- java常用类库---Math与Random类
- JAVA学习笔记13——Structs2框架第三章
- 每个程序员应该知道的最基本的东西是什么?
- 链队列的出队入队
- javaScript异步错误处理
- 使用springMVC创建REST风格的服务器
- android打开office
- tomcat与nginx配置遇到的问题
- 生物信息学常见的数据下载,包括基因组,gtf,bed,注释
- angularjs的发货,已发货切换
- Java 多线程初学
- 项目中报错汇总