Session 13 |
Deque
A stack is a conceptual structure consisting of a set of homogeneous elements and is based on the principle that the last inserted elements are retrieved first. Therefore, this data structure is also known as LIFO (last-in-first-out). It is a commonly used abstract data type with two major operations, namely push and pop.
In Java, stacks are presented by Deque
interface. The Deque
interface extends Queue
interface. The name deque is short for double ended queue. The elements are appended to the end of a deque (push
) and are removed (pop
) from the end of a stack.
// s of the Deque (double-ended queue) interface has functionality of the stack Deque<Integer> s = new ArrayDeque<>(); s.push(1); s.push(2); s.push(3); System.out.print(s.pop()); // 3 System.out.print(s.pop()); // 2 System.out.print(s.pop()); // 1
Session 13 |