题解 | #用两个栈实现队列#
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param node int整型 * @return 无 */ //声明一个全局变量 int n[1000], top = 0; int m[1000], tp=0; void push(int node ) { // write code here //判断pop栈里是否有数据,如果有,则输出到push栈 while(tp) n[top++]=m[--tp]; n[top++]=node; } int pop() { // write code here //将push栈里de数据全部输出到push栈 while(top) m[tp++]=n[--top]; return m[--tp];//成功输出数据,tp-1 }