Imagine you have tasks arriving in order and you want to process them in the same order. Why is a queue better than a list for this?
Think about how tasks should be handled in the order they come.
Queues follow first-in, first-out order, which matches how tasks should be processed fairly. Lists do not guarantee this order without extra work.
What is the printed state of the queue after these operations?
Queue<int> q = new Queue<int>(); q.Enqueue(10); q.Enqueue(20); q.Enqueue(30); q.Dequeue(); Console.WriteLine(string.Join(" -> ", q) + " -> null");
Remember dequeue removes the first item added.
After enqueueing 10, 20, 30, the queue is 10 -> 20 -> 30. Dequeue removes 10, so the queue becomes 20 -> 30.
What problem arises if we use a stack instead of a queue to process tasks arriving in order?
Think about how a stack removes items compared to a queue.
A stack uses last-in, first-out order, so the newest task is processed first, which breaks the order of arrival.
You are designing a system to manage customers waiting in line for service. Which data structure best models this scenario and why?
Think about how people wait in real lines.
Queues model real-world lines well because they serve customers in the order they arrive, which is fair and expected.
What is the final printed state of the queue after this code runs?
Queue<string> q = new Queue<string>(); q.Enqueue("A"); q.Enqueue("B"); q.Enqueue("C"); q.Dequeue(); q.Enqueue("D"); q.Dequeue(); Console.WriteLine(string.Join(" -> ", q) + " -> null");
Track each enqueue and dequeue step carefully.
Enqueue A,B,C: queue is A->B->C. Dequeue removes A: B->C. Enqueue D: B->C->D. Dequeue removes B: C->D.
