Question: python please IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as

python please IMPORTANT: For this exercise, you will be defining a functionwhich USES the Stack ADT. A stack implementation is provided to youas part of this exercise - you should not define your ownStack class. Instead, your code can make use of any of thepython please

IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not define your own Stack class. Instead, your code can make use of any of the Stack ADT methods: Stack(), push(), pop(), peek(), size() and is_empty(). Write a function called get_top_of_stack(a_stack) which takes a Stack object as a parameter, and returns the value that is on the top of the stack. If the parameter stack is empty, the function should return None. Note: your code should not update the stack. For example: Test Result 104 Stack: [100, 101, 102, 103, 104] S = Stack() S.push(100) S.push(101) s.push(102) S.push(103) s.push(104) x = get_top_of_stack(s) print(x) print(s) None S = Stack() X = get_top_of_stack(s) print(x) IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not define your own Stack class. Instead, your code can make use of the Stack ADT methods: Stack(), push(), pop(), peek(), size() and is_empty(). Write a function named reverse_integers (numbers) which takes a list of numbers as a parameter and returns a new list. The function should reverse the order of the numbers in the parameter list using a stack. For example: Test Result [1, 2, 3, 4.5] [4.5, 3, 2, 1] a_list = [1, 2, 3, 4.5] result = reverse_integers (a_list) print(a_list) print(result) IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not define your own Stack class. Instead, your code can make use of the Stack ADT methods: Stack(), push(), pop(), peek (), size() and is_empty(). Write a function named merge_two_stacks (stacki, 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. For example: Test Result Stack: [9, 7, 3, 2] Stack: [6, 5, 4, 1] Stack: [1, 2, 3, 4, 5, 6, 7, 9] $1 = Stack() s1.push_list([9, 7, 3, 2]) S2 = Stack() s2.push_list([6, 5, 4, 1]) print(51) print(2) print(merge_two_stacks (s1, s2)) Stack: [1, 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)) IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not 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 called evaluate_postfix(postfix_list) which take a list of operators and operands (all strings), representing a valid postfix expression, and the function should evaluate it. For example, the postfix expression: 243 * - which would be represented by the input list of strings: ['2', '4', '3', '*', '-') would evaluate to - 10. Note: although the parameter list consist of strings, you should convert all operands into integers. When implementing division, you should use integer division (i.e. the // operator) so that any expression will evaluate to an integer value. Hint: you will probably find it useful to use the compute(number1, number2, operator) function provided in the answer box. The function takes two operands and an operator as parameters and returns the result of applying the operator to the operands. Note: you can assume that the parameter string is a valid postfix expression. For example: Test Result 12 print(evaluate_postfix(['2', '10', '+'])) print(evaluate_postfix(['2', '4', '3', '*', '-'])) -10 print(evaluate_postfix( ['10', '4', '2', '-', '5', '*', '+', '3', '-'])) 17

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!