Question: **Please provide the answers in python and also as directed in the question. Thanks in advance** 1) Suppose, you have a stack class. You have

**Please provide the answers in python and also as directed in the question. Thanks in advance**

1) 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 helpingStackPush(), helpingStackPop(), helpingStackisEmpty(), helpingStacksize(). Assume: these are already implemented. You need to use them properly.

2) 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.

3) We have a stack class and have 5 utility functions: isempty(), push(), pop(), peek() and size(). The stack is maintaining the ascending order always. Now, you would need to insert a new value into this stack using a pushStack(value) function. Write the pushStack(value) utility function for the stack class so that the function always maintains the ascending order in the stack.

Program a simple text editor using Stack. The user will input a complete sentence. You have to put this string into a character stack. When the user selects the option to undo, a word from the stack will be deleted. By selecting undo again, another word from the stack will be removed and so on.

Hints: Create a stack for words.

4) Reverse the first k elements of a queue, push it back into the queue. For example, if the queue has members 10, 20, 30, 40 , 50 , 60 , 70, 80, 90 and first 5 numbers are asked to be reversed then the result will be 60, 70, 80, 90, 50, 40, 30, 20, 10.

5) You have two volunteers who are collecting donations from the members of a community. Suppose each of the members has a member id and they are lined up in ascending order. To keep the number of people balanced, volunteer A is collecting donations from members whose ids are divisible by 2 and volunteer B is collecting donations from members whose ids are not divisible by 2. Write a program which uses two queues, such that if the even number member id is given, it will assign that member to volunteer A, otherwise, the member will go to volunteer B.

6) Given a number n, write a function that generates and prints all binary numbers with decimal values from 1 to n. You need to use a queue for that

7) Create a myQueue class and all of its functions (enqueue, dequeue, isEmpty, peek, size). You can use only two stacks (two objects from your stack class) inside the myQueue class to hold the data. That means, you cannot use any list or double ended queue to hold data.

8) Create a myStack class and all of its functions (push, pop, isEmpty, peek, size). You can use only two queues (two objects from your queue class) inside the myStack class to hold the data. That means, you cannot use any list to hold data.

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!