Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Stacks and queues Basic operations Implementation of stacks and queues Stack and Queue in java.util Data Structures and Algorithms in Java, Third Edition Ch04–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 Edition Ch04–2 Series of operations on a stack push 5 push 9 push 4 5 9 5 pop topEl push 2 4 9 5 Data Structures and Algorithms in Java, Third Edition 9 5 9 5 Ch04–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 Edition Ch04–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 Edition Ch04–5 Series of operations on a queue enqueue 5 dequeue firstEl 5 enqueue 9 59 enqueue 7 597 97 97 Data Structures and Algorithms in Java, Third Edition enqueue 2 Ch04–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 Edition Ch04–7 Stack vs. queue dequeue enqueue pop push stack – a LIFO structure (last in, first out) queue – a FIFO structure (first in, first out) Data Structures and Algorithms in Java, Third Edition Ch04–8