0% found this document useful (0 votes)
8 views4 pages

Stack

The document contains a Python program that implements a stack using an array. It defines a class with methods to push, pop, display, and peek at the stack elements. The main section creates an instance of the stack, adds elements, and displays the current state of the stack.

Uploaded by

saaxxzz07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Stack

The document contains a Python program that implements a stack using an array. It defines a class with methods to push, pop, display, and peek at the stack elements. The main section creates an instance of the stack, adds elements, and displays the current state of the stack.

Uploaded by

saaxxzz07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM:

import array#importing array module

#creating class for stack

class st:

def __init__(self,size):

[Link]=[Link]('i',[])#declaring the idlicooker

[Link]=-1#taking papper and writing the no of plates as -1

[Link]=size #maximum no of plates in cooker

def push(self,var):#declaring the brother motu to take plate

if [Link]==[Link]-1:

print('stack is full')

else:

[Link]=[Link]+1#increasing the no of plates

[Link](var)#placing the plate into the cooker

def pop(self):#declaring another brother patlu to give plate

if [Link]==-1:
print('stack is empty')

else:

var=[Link][[Link]]#transfering the value in idle plate into


hotbox

[Link]=[Link]-1#decreasing the top value

return var#returing the hotbox to hall

def display(self):#asking assit1 to tell details for cooker

if [Link]==-1:

print('stack is empty')

else:

print('showing the values in stack')

for i in range([Link],-1,-1):

print([Link][i])

def peek(self):#asking assit2 to see and tell about top plate

if [Link]==-1:

print('stack is empty')

else:
print('the top value is',[Link][[Link]])

#this is main(this is hall)

s1=st(5)#declaring the object of cooker

[Link](10)

[Link](20)

[Link]()

[Link]()#calling assit1 to tell details for cooker

output:

You might also like