Question: 1. Take a string from the user and print it in the reverse order using stack data structure. Also prints the unicode of each
1. Take a string from the user and print it in the reverse order using stack data structure. Also prints the unicode of each character Input: WATERMELON Output: NOLEMRETAW Hint: Use the property of stack to reverse the string 2. Given a string of brackets, determine whether each sequence of brackets is balanced. If a string is balanced, print True on a new line; otherwise, print False on a new line. Input: Output 0 True 8 True [] True {0} True {(D]} False (0 False {[C]} False 3. Suppose, you have a stack class. You have 5 utility functions: isempty(), push(), pop(). peek() and size(). Write a program keepLargestOnTop(stack) in a way that the largest value in that stack would be in the TOP position always. Return the stack. Hints: You should use a helpingStack and its functions helping StackPush(), helping StackPop(), helpingStackisEmpty(), helpingStacksize(). Assume: these are already implemented. You need to use them properly. Current stack 23 53 56 19 44 TOP 22 99 After your 44 Program keepLargestOnTop(stack): Stack looks like below: 23 53 56 19 44 22 TOP 44 99 4. Given two stacks with integer values, balance the sum of integer values present in each of the stack by adding a new element in any of the stack. For example, if stack A contains 1, 5, 11 and 4 and stack B contains 4,32,- 1 and 1 then by adding 15 in stack A will balance the sum of values of both the stacks. Input: 1 4 32 11 1 4 -1 Stack A Stack B Output: 1 4
Step by Step Solution
There are 3 Steps involved in it
Ans 1 Lets implement the given problem in the Python programming language with comments to understand the code easily Define the function push to stor... View full answer
Get step-by-step solutions from verified subject matter experts
