Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help writing a program for #4 in Java! 4. (Optional) Design a circular Queue IntegerQueue: (1) Circular Queue is a linear data structure in

Need help writing a program for #4 in Java!

image text in transcribed

4. (Optional) Design a circular Queue IntegerQueue: (1) Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle Front 20 50 40 Rear (2) Basic/internal data member to serve as container: integer array of dedicate size; (3) Methods to operate on IntegerQueue: Constructor: initialize data member (generate an empty array with size of default number or dedicate number specified through input argument) front(): get the front item from queue rear(): get the last item from queue push(): insert an element (integer number) into the circular queue. The new element is always inserted at Rear position. (clue: - Check whether queue is Full: check ((rear== SIZE-1 && front == 0) || (rear== front-1)). - If it is full then return false indicating the Queue is full/failed action. If queue is not full then, check if (rear == SIZE - 1 && front != 0) if it is true then set rear=0 and insert element) pop(): delete an element from the circular queue. The element is always deleted from front position. (clue: - Check whether queue is Empty: check (front==-1). - If it is empty then return false indicate Queue is empty/failed action. If not empty, then - Check if (front=rear) if it is true then set front-rear=-1 else check if (front==size-1), if it is true then set front=0 and return the element) isEmpty(): check if the queue is empty (see logic in push()) isFull(): check if the queue is full. (see logic in pop()) getSize(: get the number of elements in queue

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_2

Step: 3

blur-text-image_3

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

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions