Recall & Review
beginner
What is the main difference between a Queue and a Stack?
A Queue follows First-In-First-Out (FIFO) order, meaning the first item added is the first removed. A Stack follows Last-In-First-Out (LIFO) order, meaning the last item added is the first removed.
Click to reveal answer
beginner
In C#, which method adds an item to a Queue?
The
Enqueue() method adds an item to the end of the Queue.Click to reveal answer
beginner
How do you remove the top item from a Stack in C#?
Use the
Pop() method to remove and return the item at the top of the Stack.Click to reveal answer
intermediate
What happens if you call
Dequeue() on an empty Queue in C#?It throws an
InvalidOperationException because there are no items to remove.Click to reveal answer
intermediate
Explain the behavior of
Peek() method in both Queue and Stack.The
Peek() method returns the next item to be removed without removing it. For a Queue, it returns the item at the front. For a Stack, it returns the item at the top.Click to reveal answer
Which method adds an element to the top of a Stack in C#?
✗ Incorrect
The Push() method adds an element to the top of the Stack.
What order does a Queue follow?
✗ Incorrect
A Queue follows First-In-First-Out (FIFO) order.
What does the Pop() method do in a Stack?
✗ Incorrect
Pop() removes and returns the top item of the Stack.
Which method removes the front item from a Queue?
✗ Incorrect
Dequeue() removes and returns the front item of the Queue.
What will happen if you call Peek() on an empty Stack?
✗ Incorrect
Calling Peek() on an empty Stack throws InvalidOperationException.
Describe how Queue and Stack differ in the order they remove items.
Think about a line of people versus a stack of plates.
You got /4 concepts.
Explain the purpose of the Enqueue, Dequeue, Push, and Pop methods in C# collections.
Match methods to adding or removing items in Queue or Stack.
You got /4 concepts.