public class Q1 {
private final Stack<Integer> newest =new Stack<>();
private final Stack<Integer> oldest=new Stack<>();
void enqueue(Integer e){
newest.push(e);
}
private void shift(){
while(!newest.empty()){
oldest.push(newest.pop());
}
}
Integer deque(){
shift();
return oldest.pop();
}
}
and below tests
class Q1Test {
Q1 testee = new Q1();
@Test
void enqueue() {
for (int i = 0; i < 10; i++) {
testee.enqueue(i);
}
System.out.println(testee.deque());
for (int i = 11; i < 22; i++) {
testee.enqueue(i);
}
System.out.println(testee.deque());
}
@Test
void deque() {
}
}