Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a segment of code (application level) to perform each of the following ope

ID: 675383 • Letter: W

Question

Write a segment of code (application level) to perform each of the following operations. Assume myQueue is an object of the class ArrayUnbndQueue. You may call any of the public methods. You may also declare additional queue objects.

a. Set secondElement to the second element from the beginning of myQueue, leaving myQueue without It's original two front elements.

b. Set rear equal to the rear element in myQueue, leaving myQueue empty.

c. Set rear equal to the rear element in myQueue, leaving myQueue unchanged.

d. Print out the contents of myQueue, leaving myQueue unchanged.

Explanation / Answer

(a)
{
queue.Dequeue(secondElement);
queue.Dequeue(secondElement);
}

(b)

{

while (!queue.IsEmpty())
queue.Dequeue(last);
}

(c)

{
QueType tempQ;
ItemType item;
while (!queue.IsEmpty())
{
queue.Dequeue(last);
tempQ.Enqueue(last);
}
while (!tempQ.IsEmpty())
{
tempQ.Dequeue(item);
queue.Enqueue(item);
}
}

(d)

{
QueType<ItemType> tempQ;
ItemType item;
while (!queue.IsEmpty())
{
queue.Dequeue(item);
tempQ.Enqueue(item);
}
while (!tempQ.IsEmpty())
{
tempQ.Dequeue(item);
queue.Enqueue(item);
copy.Enqueue(item);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote