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);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.