网站意见反馈源码,muse to wordpress,WordPress静态文件生成,2019年最好的国外vps实现一个队列#xff0c;队列初始为空#xff0c;支持四种操作#xff1a;
push x – 向队尾插入一个数 xx#xff1b;pop – 从队头弹出一个数#xff1b;empty – 判断队列是否为空#xff1b;query – 查询队头元素。
现在要对队列进行 MM 个操作#xff0c;其中的…实现一个队列队列初始为空支持四种操作
push x – 向队尾插入一个数 xxpop – 从队头弹出一个数empty – 判断队列是否为空query – 查询队头元素。
现在要对队列进行 MM 个操作其中的每个操作 3 和操作 4 都要输出相应的结果。
输入格式
第一行包含整数 M表示操作次数。
接下来 M 行每行包含一个操作命令操作命令为 push xpopemptyquery 中的一种。
输出格式
对于每个 empty 和 query 操作都要输出一个查询结果每个结果占一行。
其中empty 操作的查询结果为 YES 或 NOquery 操作的查询结果为一个整数表示队头元素的值。
数据范围
1≤M≤100000, 1≤x≤109, 所有操作保证合法。
输入样例
10
push 6
empty
query
pop
empty
push 3
push 4
pop
query
push 6输出样例
NO
6
YES
4
_____________________________________________________________________________
一如既往的用数组模拟队列
写作不易点个赞呗!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
不习惯用
_____________________________________________________________________________
题目要求的
#include bits/stdc.h
using namespace std;
int que[1000005],a1,b,n,y;
string x;
void push(int x){将x加入队尾que[b]x;
}
void pop(){删除队首a;
}
void query(){输出队首元素coutque[a]endl;
}
void empty(){判断队列是否为空if(b-a10)coutYESendl;else coutNOendl;
}
int main(){cinn;for(int i1;in;i){cinx;if(x[0]px[1]u){ciny;push(y);}else if(x[0]p)pop();else if(x[0]q)query();else if(x[0]e)empty();}
} 修改了query并增添了一些功能:
#include bits/stdc.h
using namespace std;
int que[1000005],a1,b,n,y;a表示对首的位置b表示队尾的位置
string x;
void push(int x){将x加入队尾que[b]x;
}
void pop(){删除队首a;
}
void front(){输出队首元素coutque[a]endl;
}
void empty(){判断队列是否为空if(b-a10)coutYESendl;else coutNOendl;
}
void back(){输出对尾coutque[b];
}
void size(){返回队列中元素个数couta-b1;
}
int main(){cinn;for(int i1;in;i){cinx;if(x[0]px[1]u){ciny;push(y);}else if(x[0]p)pop();else if(x[0]f)front();else if(x[0]e)empty();else if(x[0]b)back();else if(x[0]s)size();}
}