Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C++ project and add the two files to it. Take a look at the queue implementation defined in class. Here is an example

Create a C++ project and add the two files to it.

Take a look at the queue implementation defined in class. Here is an example of a queue with wrap-around:

data

C

X

R

B

[0] [1] [2] [3] [4] [5]

front rear queue_size

3 1 6

We are interested in writing a loop that will look at each element in the queue.

1. Write an expression that gives the index of the first element of the queue. Make sure that the expression works for all cases (including when the front element wraps around).

2. Write an expression that gives the index of the last element of the queue.

3. Without wrap-around the loop would be simple to write (where first_index is your answer to question 1 and last_index is your answer to question 2):

for (i = first_index; i <= last_index; i++)

a. What would we need to change i++ to so that it will work for the wrap-around case?

b. Even after this change, i <= last_index will still cause a problem. Explain why.

4. Instead, we will use the following code which will stop when i is past the last index in the queue:

for (i = first_index; i != last_index + 1; increment i)

where we are printing each element in turn.

cout << data [i];

Write the expression for last_index + 1 with wrap-around.

Make the following changes to the implementation file:

Finish writing the queue member function called elements that returns the number of elements in a queue. It should use the loop described above to move through the elements in the queue to count them. It should return the number counted. The function should work if the queue is empty (should return 0).

int elements ();

Finish writing the queue member function called print that prints the elements in the queue on a single line. It should use the loop described above to move through the elements in the queue to print them. If the queue is empty, it should not print anything.

void print ();

Make the following changes to the application file (there are comments to help instruct you where to place each item):

Declare a queue called qute.

the queue.

Print the number of elements in the queue (add to the cout).

the characters H, I, P, P and O on the queue.

the queue.

Print the number of elements in the queue.

the queue three times.

the characters K, E and R on the queue.

the queue.

Print the number of elements in the 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

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago