Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an item to the end of a queue.
DSA C#
Queue<int> numbers = new Queue<int>(); numbers.[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Push which is for stacks, not queues.
Using Add which is not a method of Queue.
✗ Incorrect
In C#, Enqueue adds an item to the end of a queue.
2fill in blank
mediumComplete the code to remove the last item added to a stack.
DSA C#
Stack<string> books = new Stack<string>();
string lastBook = books.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using Dequeue which is for queues, not stacks.
Using Peek which only views the top item without removing it.
✗ Incorrect
Pop removes and returns the last item added to a stack.
3fill in blank
hardFix the error in the code to check the next item to be removed from a queue without removing it.
DSA C#
Queue<char> letters = new Queue<char>();
char nextLetter = letters.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using Pop which removes from a stack, not a queue.
Using Dequeue which removes the item.
✗ Incorrect
Peek returns the next item in the queue without removing it.
4fill in blank
hardFill both blanks to create a stack and add an item to it.
DSA C#
Stack<int> numbers = new [1]<int>(); numbers.[2](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Queue instead of Stack.
Using Enqueue which is for queues.
✗ Incorrect
Use Stack to create a stack and Push to add an item.
5fill in blank
hardFill all three blanks to create a queue, add an item, and remove the first item.
DSA C#
Queue<string> tasks = new [1]<string>(); tasks.[2]("Email"); string firstTask = tasks.[3]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using Stack instead of Queue.
Using Push or Pop which are for stacks.
✗ Incorrect
Create a Queue, add with Enqueue, and remove with Dequeue.
