题解 | #用两个栈实现队列#

用两个栈实现队列

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;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务