Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with a program in c++. A circular queue (https://en.wikipedia.org/wiki/Circular_buffer) is one way to implement a queue in the computer. In this assignment,

I need help with a program in c++.

image text in transcribedimage text in transcribed

A circular queue (https://en.wikipedia.org/wiki/Circular_buffer) is one way to implement a queue in the computer. In this assignment, you will implement a CircularQueue class that stores chars, with the following characteristics A circular queue is stored in an array In addition to the array, the data structure keeps track two indices in the array: a 'start" position, and an end position. When an item is enqueued (added) to the queue, it is added at the end position. The end position is then incremented, wrapping around to zero it reaches the end of the array To dequeue (remove and return) an item from the queue, we return the item at the start position, and increment the start position (once again wrapping around when it reaches the end of the array). If start and end are the same, then the queue is empty. if ( end+1 ) % arrayLength-start, then the queue is full. To add another element to the queue, a new array must be allocated with twice the size of the current one, and all of the elements copied to it, starting at position 0. In C++, after the copying, the old array should be deleted to avoid a memory leak Write a class called CircularQueue, or something similar, that implements a circular queue for chars as described above, using an array of chars as the array storage. The queue should start out with an array of length 2. Write a program that uses your CircularQueue class to answer queries that either add letters to the queue, or remove them from the queue. When a letter is removed from the queue, print out both the letter's position in the array, and the letter itself

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

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions