Question: all coding is on python 3. Create a class DStack to implement two stacks in one array A[1....n] in such a way that neither stack

all coding is on python 3. Create a class DStack to implementall coding is on python

3. Create a class DStack to implement two stacks in one array A[1....n] in such a way that neither stack overflows unless the total number of elements in both stacks together is size n. The Push and Pop operations should run in O(1). The class should implement following functions: a. Write a constructor that takes an integer size' as argument and creates an array for size' number of elements. b. Write a function Push that inserts an element for the stack 's'. c. Write a function Pop that removes an element for the stack 's'. d. Write a function Peek that returns an element for the stack 's'. e. Write a function IsEmpty that returns true stack 's' is empty. f. Write a function Count that returns the number of elements in stack s? class DStack: # size = number of elements def _init__(self, size): 17 your code goes here # s = 1 or 2 def Push (self, s, value): // your code goes here # stack = 1 or 2 def Pop (self, s): 1/ your code goes here # s = 1 or 2 def Peek (self, s): // your code goes here # s = 1 or 2 def IsEmpty (self, s): // your code goes here # s = 1 or 2 def Count (self, s): // your code goes here Example: ds = DStack (10) ds. Push (1,10) #push 10 in stack 1 ds. Push (2,20) #push 20 in stack 2 ds. Push (1,30) #push 30 in stack 1 print (ds. Pop (1)) #pop from stack 1 print (ds. Peek (2)) # peek from stack 2 #the function should reti return

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!