Question: Please write the functions in python, include explanation for each line of code and include a screenshot of the function to view correct indentation Define
Please write the functions in python, include explanation for each line of code and include a screenshot of the function to view correct indentation Define the function using the Stack ADT Don't define your own Stack class instead your code can make use of any the Stack ADT methods: Stack(), push(), pop(), peek(), size() and is_empty(). Write a function named merge_two_stacks(stack1, stack2) which takes two SORTED (i.e. smallest element at the top) stacks as parameters and returns a new stack. The function should merge the two parameters stack into a new one, such that the elements become arranged in reverse sorted order (i.e. largest element at the top). Note: the size of the two parameter stacks may differ.
| Test | Result |
s1 = Stack() s1.push_list([9, 7, 3, 2]) s2 = Stack() s2.push_list([6, 5, 4, 1]) print(s1) print(s2) print(merge_two_stacks(s1, s2)) | Stack: [9, 7, 3, 2] Stack: [6, 5, 4, 1] Stack: [1, 2, 3, 4, 5, 6, 7, 9] |
s1 = Stack() s1.push_list([9, 7]) s2 = Stack() s2.push_list([6, 5, 4, 1]) print(merge_two_stacks(s1, s2)) | Stack: [1, 4, 5, 6, 7, 9] |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
