Question
Show what is written by the following segments of code, given that item1, item2, and item3 are int variables. a. QueType queue; item1 = 1;
Show what is written by the following segments of code, given that item1, item2, and item3 are int variables.
a.
QueType
item1 = 1;
item2 = 0;
item3 = 4;
queue.Enqueue(item2);
queue.Enqueue(item1);
queue.Enqueue(item1 + item3);
queue.Dequeue(item2);
queue.Enqueue(item3*item3);
queue.Enqueue(item2);
queue.Enqueue(3);
queue.Dequeue(item1);
cout << item1 << endl << item2 << endl << item3
<< endl;
while (!queue.IsEmpty())
{
queue.Dequeue(item1);
cout << item1 << endl;
}
b.
QueType
item1 = 4;
item3 = 0;
item2 = item1 + 1;
queue.Enqueue(item2);
queue.Enqueue(item2 + 1);
queue.Enqueue(item1);
queue.Dequeue(item2);
item1 = item2 + 1;
queue.Enqueue(item1);
queue.Enqueue(item3);
while (!queue.IsEmpty())
{
queue.Dequeue(item3);
cout << item3 << endl;
}
cout << item1 << endl << item2 << endl << item3 << endl;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started