Lab 05
Lab 05
1. Push Stack
Please initialize a Stack with the data type of the elements stored inside the Stack as Integer. Then, add (push)
elements onto the top of the Stack using the push() method. Check the status of the stack before and after adding
the element.
Examples
Input Output
20, 13, 89, 90, 90, Element Stack: [20, 13, 89, 90, 11, 45, 18]
11, 45, 18
Output
Page 1 of 6
The process of pushing elements 20, 13, 89, 90, 11, 45, 18 to the above Stack is illustrated as below:
Examples
Output
Page 2 of 6
The process of deleting 3 elements on the top of the Stack is: 18, 45, 11 is illustrated as below
3. Loop Stack
Use a Foreach loop to traverse the Stack just created above and change the value of 1 element during the traversal
process.
Examples
Output
4. Queue
You create the Queue then:
Page 3 of 6
Add data to Queue in 2 ways
Delete data in 2 ways
Get the first element from the Queue in 2 ways
Examples
Output
Page 4 of 6
In TaskProcessor, create the processTasks method to process tasks from the queue and display task
information.
Write a test program that creates tasks, adds them to the queue, and processes the queue using
TaskProcessor.
Examples
Page 5 of 6
Output
Page 6 of 6