Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started