Question: Stack and Queue are two widely used data structures. Stack has theproperty LIFO ( last in first out ) , while Queue has the property

Stack and Queue are two widely used data structures. Stack has theproperty LIFO (last in first out), while Queue has the property FIFO(first in first out). In this task, you are required to implement two generic classes: Stack and Queue. You should define the operations push and pop in the Stack class and enqueue and dequeue in the Queue class. Under the hood, you can use an ArrayList to store data items. The following figures show you the data structures.
Implement the following functionalities:
Requirements:
The generic class Stack should contain the following methods:
- push: this method pushes a data item onto the stack
- pop: this method pops the latest added data item from the stack. The method may throw runtime exceptions when it is invoked on an empty stack.
- hasItems: this method returns true if the stack is not empty and false otherwise.
The generic class Queue should contain the following methods:
- enqueue: this method adds a new data item into the queue.
- dequeue: this method returns the oldest data item from the queue and returns it.
- hasItems: this method returns true if the queue is not empty and false otherwise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!