Question: Could someone please help me complete the #TODO part, please only help with implementing four (peek, reverse_top_two, remove_all, remove_all_but_one) functions in Part 1. Users >

 Could someone please help me complete the #TODO part, please onlyhelp with implementing four (peek, reverse_top_two, remove_all, remove_all_but_one) functions in Part 1.

Users > PC > Desktop > \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Part 1 \# In

Could someone please help me complete the #TODO part, please only help with implementing four (peek, reverse_top_two, remove_all, remove_all_but_one) functions in Part 1.

Users > PC > Desktop > \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# Part 1 \# In this part of the prep, you will various stack and Queue functions. \# You must NOT access any attributes of the stack/Queues passed into each \# function. \# \# You may ONLY use the is_empty(), push(), and pop() methods of stack, and \# the is_empty(), enqueue(), and dequeue() methods of Queue. \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# def peek(stack: Stack) Optional[Any] : "" "Return the top item on the given stack. If the stack is empty, return None. Unlike Stack.pop, this function should leave the stack unchanged when the function ends. You can (and should) still call pop and push, just make sure that if you take any items off the stack, you put them back on! >>> stack =stack() \> stack.push(1) >>> stack.push(2) >>> peek (stack) 2 \>> stack.pop() 2 \# TODO: Implement this function. def reverse_top_two(stack: Stack) None: Precondition: stack> has at least two items. \>> stack = Stack() \>> stack.push(1) \>> stack. push(2) >>> reverse_top_two(stack) >> stack.pop() 1 >>> stack. pop() 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!