Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an item onto the stack.
DSA C#
Stack<int> stack = new Stack<int>(); stack.[1](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add or Append which are not stack methods.
Trying to use Insert which is for lists.
✗ Incorrect
The Push method adds an item to the top of the stack.
2fill in blank
mediumComplete the code to remove the top item from the stack.
DSA C#
Stack<string> stack = new Stack<string>(); stack.Push("apple"); string top = stack.[1]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove or Delete which are not stack methods.
Trying to use Take which is not a stack method.
✗ Incorrect
The Pop method removes and returns the top item from the stack.
3fill in blank
hardFix the error in the code to check the top item without removing it.
DSA C#
Stack<char> stack = new Stack<char>(); stack.Push('A'); char top = stack.[1]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using Pop which removes the item.
Using Top or Front which are not stack methods.
✗ Incorrect
The Peek method returns the top item without removing it.
4fill in blank
hardFill both blanks to create a stack and check if it is empty.
DSA C#
Stack<double> stack = new [1]<double>(); bool isEmpty = stack.[2] == 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using List instead of Stack.
Using Length which is not a property of Stack.
✗ Incorrect
Create a stack with Stack and check if Count is zero to know if it's empty.
5fill in blank
hardFill all three blanks to push items and then pop the top item.
DSA C#
Stack<string> stack = new [1]<string>(); stack.[2]("first"); stack.[2]("second"); string top = stack.[3]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add instead of Push.
Using Push to remove items.
✗ Incorrect
Create a stack with Stack, add items with Push, and remove the top with Pop.
