数据结构_队列_用链表动态建立释放节点实现队列各种操作_C++实现
来源:互联网 发布:java参数&传递 编辑:程序博客网 时间:2024/04/26 22:09
"mqueue.h"
#include<iostream>using namespace std;class NODE{public:NODE();int num;NODE* next;};NODE::NODE(){num=0;next=NULL;}class QUEUE{public:QUEUE();void Push();void Pop();void Front();void Length();private:NODE *front,*rear,*keep;int len;};QUEUE::QUEUE(){keep=front=rear=NULL;len=0;}void QUEUE::Pop(){cout<<"Pop Called !"<<endl<<endl;if(front==rear){if(front==NULL)cout<<"Queue Empty !"<<endl<<endl;else{delete front;front=rear=NULL;len--;}}else{keep=front->next;delete front;front=keep;len--;}}void QUEUE::Push(){cout<<"Push Called !"<<endl<<endl;int num;cout<<"Please Input The Number You Want To Push In This Queue :"<<endl<<endl;cin>>num;if(rear==NULL)front=rear=new NODE;else{rear->next=new NODE;rear=rear->next;}rear->num=num;len++;}void QUEUE::Front(){cout<<"Front Called !"<<endl<<endl;if(front==NULL){cout<<"Queue Empty !"<<endl<<endl;return;}cout<<"The Element At The Top Of The Queue Is : "<<front->num<<endl<<endl;}void QUEUE::Length(){cout<<"The Length Of This Queue Is : "<<len<<endl<<endl;}
"main.cpp"
#include<iostream>#include"mqueue.h"using namespace std;int main(){QUEUE q;char choice;while(1){cout<<"Your Choice , Please :"<<endl<<endl<<"1 . Push"<<endl<<"2 . Pop"<<endl<<"3 . Length"<<endl<<"4 . Front"<<endl<<endl;cin>>choice;switch(choice){case '1':q.Push();break;case '2':q.Pop();break;case '3':q.Length();break;case '4':q.Front();break;default:cout<<"Please Input The Right Choice As Shown Above !"<<endl<<endl;break;}}}
- 数据结构_队列_用链表动态建立释放节点实现队列各种操作_C++实现
- 数据结构_循环队列相关操作_C语言源代码
- 数据结构_串_串的一些操作_C++实现
- 数据结构的C实现_链式队列
- 数据结构的C实现_循环队列
- 14-数据结构_队列-算法实现
- 数据结构的C实现_循环队列
- 数据结构_队列-循环队列实现模拟舞伴配对问题
- 数据结构_队列-循环队列实现模拟舞伴配对问题
- 数据结构_树_二叉树的建立、遍历、复制与移除_二叉链表存储_C++实现
- 队列_数组实现 [循环队列]
- 数据结构_链表_稀疏多项式求值_C++实现
- 数据结构_链表_多项式求导_C++实现
- 数据结构_树_赫夫曼树及赫夫曼编码_C++实现
- 队列_链表实现
- 数据结构_使用二叉堆实现优先队列
- 数据结构基础8_循环队列(顺序实现)
- 数据结构_链队列相关操作
- 实时向客户端输出数据(例如1秒输出一行) 要注意的两个问题
- java.lang.OutOfMemoryError: Java heap space 解决方法
- 即时显示缩略图
- JDBC的应用
- C#用正则表达式截取字符串两种办法
- 数据结构_队列_用链表动态建立释放节点实现队列各种操作_C++实现
- 不同主机同一用户之间SSH信任关系的建立
- AsyncTask的用法
- ANT 下载及配置使用方法
- rpm常用命令及rpm参数介绍
- Struts2验证
- SQL Server 中的数据类型
- AIX 程序包
- SQLite 入门教程(三)好多约束 Constraints