import java.util.Stack;
public class Demo08 {
static Stack<Object> A=new Stack<>();
static Stack<Object> B = new Stack<>();
public Demo08(){
}
public void add(int value){
A.push(value);
}
public int delete(){
while(!A.empty()){
B.push(A.pop());
}
int result = B.empty() ? -1 : B.pop();
while(!B.empty()){
A.push(B.pop());
}
return result;
}
public static void main(String[] args) {
A.push("one");
A.push("two");
A.push("three");
B.push(3);
A.add(4);
System.out.println(A);
System.out.println(B);
}
}

Java怎么实现队列头部删除元素尾部插入元素啊?可以用两个栈,但是全部的实现代码我不会写,希望能够帮我解答一下
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-