Which code segment should you use?

You need to create a method to clear a Queue named q.
Which code segment should you use?

You need to create a method to clear a Queue named q.
Which code segment should you use?

A.
foreach (object e in q) {

B.
Dequeue();
}
foreach (object e in q) {
Enqueue(null);
}

C.
q.Clear();

D.
q.Dequeue();

Explanation:
Simply call the Clear() method to empty a queue.
A Dequeuing all of the items in a queue will also serve the same affect but it is a lot more roundabout.
B attempts to re-queue items that are already in the queue
D will de-queue only one item that is at the front of the queue.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


networkmanagers

networkmanagers

I choose C