Question: GENERAL HINT: save values in local variables! Even if you pop an item off of a stack, it's not gone forever if you assign it

GENERAL HINT: save values in local variables! Even if you pop anGENERAL HINT: save values in local variables! Even if you pop an item off of a stack, it's not "gone forever" if you assign it to a variable. """ from typing import Any, Optional from adts import Stack, 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 """ pass def swap_top_two(stack: Stack) -> None: """Swap the top two elements on . Precondition: has at least two items. >>> stack = Stack() >>> stack.push(1) >>> stack.push(2) >>> swap_top_two(stack) >>> stack.pop() 1 >>> stack.pop() 2 >>> stack.is_empty() True """ pass def has_at_least(queue: Queue, n: int) -> bool: """Return true iff queue contains at least n items. Precondition: n >= 0 >>> queue = Queue() >>> queue.enqueue(1) >>> queue.enqueue(2) >>> queue.enqueue(3) >>> has_at_least(queue, 3) True """ pass def remove_all_but_one(queue: Queue) -> None: """Remove all items from the given queue except the last one. Precondition: contains at least one item. or: not queue.is_empty() >>> queue = Queue() >>> queue.enqueue(1) >>> queue.enqueue(2) >>> queue.enqueue(3) >>> remove_all_but_one(queue) >>> queue.is_empty() False >>> queue.dequeue() 3 >>> queue.is_empty() True """ pass

PLEASE COMPLETE THE FOLLOWING INCOMPLETE FUNCTIONS ACCORDING TO THEIR DOCSTRINGS IN PYTHON 3.8

THE PICTURE IS OF A STACK IMPLEMENTATION AND HAS TO DO WITH THE ADTS PORTION OF THE CODE

class Stack : def init (00000000000000000): 00000000000000000 .fuscati =[ ] ; def is_empty (00000000000000000 ): return (00000000000000000 .fuscatl==[ ]and True) def push (00000000000000000 ,00000000000000000 ):00000000000000000 .fuscati .append (00000000000000000) def pop (00000000000000000 ):return 00000000000000000 .fuscati .pop() #e9015584e6a44b14988f13e2298bcbf9 class Queue : def init (00000000000000000 ): 00000000000000000 .fuscati =[] ; def is_empty (00000000000000000 ): return (00000000000000000 .fuscatl==[ ]and True) def enqueue (00000000000000000 ,00000000000000000 ):00000000000000000 .fuscati .append (00000000000000000) def dequeue (00000000000000000):return 00000000000000000 .fuscati .pop (0) #e9015584e6a44b14988f13e2298bcbf9

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!