About Question enthuware.ocpjp.v8.2.1133 :
Posted: Fri Apr 13, 2018 11:17 pm
Hi,
The following statement confused me.
"Since Stack is a LIFO structure (Last In First Out i.e. add to the front and remove from the front), it provides methods push(e) and pop() for this purpose, where push adds to the front and pop removes from the front"
I think it should be like "where push adds to the back and pop removes from the back"
For example, I tried the below code..
When stack is commented it prints [3,2,1] and when the Deque is commented it prints [1,2,3].
I believe its because, deque is pushing in the front and stack is pushing in the back. Am I wrong?
Regards,
Shamran.
The following statement confused me.
"Since Stack is a LIFO structure (Last In First Out i.e. add to the front and remove from the front), it provides methods push(e) and pop() for this purpose, where push adds to the front and pop removes from the front"
I think it should be like "where push adds to the back and pop removes from the back"
For example, I tried the below code..
Code: Select all
Deque<Integer> q = new LinkedList<>();
//Stack<Integer> q = new Stack<Integer>();
q.push(1);
q.push(2);
q.push(3);
System.out.println(q);
I believe its because, deque is pushing in the front and stack is pushing in the back. Am I wrong?
Regards,
Shamran.