import java.util.*;
public class Solution{
public void appendTail(Stack<Integer> s,int a){
s.push(a);
}
public void deleteHead(Stack<Integer> s){
if(s.isEmpty()){
System.out.println("queue is empty");
return;
}
Stack<Integer> stack=new Stack<>();
while(!s.isEmpty()){
stack.push(s.pop());
}
stack.pop();
while(!stack.isEmpty()){
s.push(stack.pop());
}
return;
}
public static void main(String args[]){
Stack<Integer> s=new Stack<>();
s.push(1);
s.push(2);
s.push(3);
Solution sl=new Solution();
sl.appendTail(s,4);
sl.deleteHead(s);
}
}
7、用两个栈实现队列
最新推荐文章于 2021-11-03 16:26:58 发布