Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the top of the stack.
Data Structures Theory
stack.[1](element) Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'pop' which removes an element instead of adding.
Using 'peek' which only views the top element without removing or adding.
β Incorrect
The push operation adds an element to the top of the stack.
2fill in blank
mediumComplete the code to remove the top element from the stack.
Data Structures Theory
top_element = stack.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'push' which adds instead of removing.
Using 'peek' which only views the top element without removing it.
β Incorrect
The pop operation removes and returns the top element of the stack.
3fill in blank
hardFix the error in the code to view the top element without removing it.
Data Structures Theory
top_element = stack.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'pop' which removes the element instead of just viewing it.
Using 'push' which adds an element instead of viewing.
β Incorrect
The peek operation returns the top element without removing it from the stack.
4fill in blank
hardFill both blanks to add an element and then view the top element.
Data Structures Theory
stack.[1](new_item) top = stack.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'pop' instead of 'peek' to view the top element.
Using 'remove' which is not a standard stack operation.
β Incorrect
First, push adds the new item to the stack. Then, peek shows the top element without removing it.
5fill in blank
hardFill all three blanks to push an element, pop the top, and then peek at the new top.
Data Structures Theory
stack.[1](item) popped = stack.[2]() current_top = stack.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Mixing up push and pop operations.
Using 'remove' which is not a stack operation.
β Incorrect
First, push adds the item. Then, pop removes the top element. Finally, peek shows the new top element.