Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ program A queue is an abstract data type for adding and removing elements. The first element added to a queue is the first element

c++ program image text in transcribed
image text in transcribed
A queue is an abstract data type for adding and removing elements. The first element added to a queue is the first element that is removed (first-in-first-out, FIFO). One way to implement Queues is to use circular arrays. The idea of a circular array is that the end of the array wraps around" to the start of the array. To implement such an array, you have to keep track of at least two variables: (1) head: it is an index that changes every time you dequeue (delete an element), and (2) tail: it is an index that changes every time you enqueue (insert and element). Optionally, you can keep track of a third variable, size, to know the number of elements that exists in the array (we won't for now) headtal head head tail tail 7 Initially, both head and tail has value 0. If you enqueue the number 5, the head stays at 0, but the tail increments by 1. If you enqueue the number 1, the head also remains at 0, and the tail becomes 2. If you dequeue a number, the head increments by 1, but the tail remains unchanged. Note that the tail cannot cross over the head and should always point to an element that is either empty or previously dequeued. The CircArrayQueue class will have 3 data members: a dynamically allocated array, a head, and a tail index (integers). You need to appropriately implement the constructor (default constructor (size 5)+ constructor that accepts a size parameter), the desctoru, copy constructor, and implement the assignment operator. Then you need to support the following functionality: vold enqueue(int element): //inserts element to tail of queue or prints "Queue is full" when queue is full int dequeue://removes integer from head of queue bool isEmptyO://checks if queue is empty bool isFullO://checks if queue is full int getHead0://returns the value of head int getTail0://returns the value of tail int size0://returns the size of the queue string toString0://outputs the queue elements as follows "[el, e2,...]" Test your code by using the following sequence of operations: cout

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions