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怎末实现,怎末来输出这些,就是在力扣中只给了功能代码部分,我不知道在java中该怎末写完整的,怎么输出的那些结果。
还有就是在算法中出现的算法都需要敲一遍吗,还是需要了解思想就可以?比如我就是思想能懂,但是我还是敲不出来。希望大家能给个解答。
给我一个完整的代码参考下。
题目如下