Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

Students also viewed these Databases questions

Question

Compare a delusion with a hallucination.

Answered: 1 week ago