Practice.3_YU My Queue
来源:互联网 发布:ftp服务器软件绿色版 编辑:程序博客网 时间:2024/05/21 22:59
/* B. My Queue 请实现一个MyQueue类,实现出队,入队,求队列长度. 实现入队函数 void push(int x); 实现出队函数 int pop(); 实现求队列长度函数 int size(); Input Specification: 每个输入包含1个测试用例。每个测试用例第一行给出一个正整数 n (n <= 10^6) ,接下去n行每行一个数字,表示一种操作: 1 x : 表示从队尾插入x,0<=x<=2^31-1。 2 : 表示队首元素出队。 3 : 表示求队列长度。 Output Specification: 对于操作2,若队列为空,则输出 “Invalid”,否则请输出队首元素。 对于操作3,请输出队列长度。 Sample Input: 5 3 2 1 100 3 2 Sample Output: 0 Invalid 1 100 */#include <iostream>#include <iomanip>using namespace::std;struct node{ int num; node* next;};class MyQueen{ node*head;public: void push(int x); void pop(); int size();}queen;void MyQueen::push(int x){ node *p=new node; node*q; p->num=x; if(head==NULL) { head=p; return; } for(q=head;q->next!=NULL;q=q->next); q->next=p;}void MyQueen::pop(){ if(head==NULL) { cout<<"Invalid"<<endl; return; } cout<<head->num<<endl; head=head->next; return;}int MyQueen::size(){ int count=0; node* p; for(p=head;p!=NULL;p=p->next,count++); return count;}int main(){ int x,y,repeat; cin>>repeat; while(repeat--) { cin>>x; switch (x) { case 1: cin>>y; queen.push(y); break; case 2:queen.pop();break; case 3:cout<<queen.size()<<endl;break; } }}}}
0 0
- Practice.3_YU My Queue
- Practice.3_YU 宿舍谁最高?
- Practice.3_YU 求日期和时间
- Actual Practice : Table Valued Functions in my work -3
- My PL/SQL practice --8/2/10
- My Queue ADT 链表实现
- My understand of stack and queue
- Review Dijkstra's algorithm and practice my English
- Actual Practice : DATEADD & DATEDIFF in my work - 1
- Actual Practice : Scalar Valued Functions in my work - 2
- Actual Practice : Insert into select from in my work -5
- Actual Practice : Scripts Integration in my work - 6
- english practice No.3
- practice
- practice
- Queue 3
- Actual Practice : [with CTE]&[convert]&[coalesce] as in my work - 4
- queue(3)--freebsd中的queue结构使用
- Practice.3_YU 求日期和时间
- Sublimetext查看代码的编码方式
- Android中如何将原生程序向stdout和stderr的输出重定向到logcat
- 最大似然估计、最大后验估计和贝叶斯估计的关系
- Windows Phone 8.1中的.xaml文件开头那些奇怪的定义
- Practice.3_YU My Queue
- 黑马程序员——String类与this关键字
- 由于对必需的库Java\jdk1.7.0\jre\lib\rt.jar 具有一定限
- c语言之题1
- Oracle学习(一)之控制文件重命名
- css3学习笔记(二)---选择器(包含部分css2选择器)
- 视频与图像RGB/YUV格式详解
- hdoj 2094 产生冠军 【水】
- 抽象方法和接口的区别