java栈的写法
Stackstack = new Stack<>(); stack.isEmpty(); stack.push(1); stack.pop(); stack.peek(); // 返回栈顶 stack.size();
class CQueue { Stackstack1; Stack stack2; public CQueue() { stack1 = new Stack<>(); stack2 = new Stack<>(); } public void appendTail(int value) { stack1.push(value); } public int deleteHead() { if(!stack2.isEmpty()) return stack2.pop(); if(stack1.isEmpty()) return -1; while(!stack1.isEmpty()){ stack2.push(stack1.pop()); } return stack2.pop(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)