题解 | #用两个栈实现队列#
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param node int整型
* @return 无
*/
static int stack1[1000];
static int top1=0;
static int stack2[1000];
static int top2=0;
void push(int node ) {
// write code here
stack1[top2++]=node;
//top2=0;
// for(int i=0;i<top1;i++)
// {
// stack2[top2++]=stack1[top1-1-i];
// }
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param 无
* @return int整型
*/
int pop() {
// write code here
//top1=0;
int ans=stack1[top1];
top1++;
//top1=0;
//for(int i=0;i<top2;i++)
// {
// stack1[top1++]=stack2[top2-1-i];
// }
return ans;
}
查看15道真题和解析