Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third EditionCh04 – 1
Stack operations push(el) put the element el on the top of the stack; pop() take the topmost element from the stack; topEl() return the topmost element in the stack without removing it; clear() clear the stack; isEmpty() check to see if the stack is empty; Data Structures and Algorithms in Java, Third EditionCh04 – 2
Series of operations on a stack poptopEl 9595 push 4push 9push 5push Data Structures and Algorithms in Java, Third EditionCh04 – 3
Applications of stacks delimiter matching operations on long integers history of visited pages through a Web browser undo sequence in a word processor sequence of method/function calls Data Structures and Algorithms in Java, Third EditionCh04 – 4
Queue enqueue(el) put the element el at the end of the queue; dequeue() take the first element from the queue; firstEl() return the first element in the queue without removing it; clear() clear the queue; isEmpty() check to see if the queue is empty; Data Structures and Algorithms in Java, Third EditionCh04 – 5
Series of operations on a queue enqueue 5 5enqueue 9 5 9enqueue 7 dequeue 9 7 firstEl 9 7enqueue Data Structures and Algorithms in Java, Third EditionCh04 – 6
Applications of queues waiting lines in simulation problems scheduling processes by the operating system access to shared resources Data Structures and Algorithms in Java, Third EditionCh04 – 7
Stack vs. queue push pop enqueue dequeue stack – a LIFO structure (last in, first out) queue – a FIFO structure (first in, first out) Data Structures and Algorithms in Java, Third EditionCh04 – 8