Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedall 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

2. How should this be dealt with by the organisation?

Answered: 1 week ago

Question

explain what is meant by the term fair dismissal

Answered: 1 week ago