Computer Science, asked by ashreya1906, 1 month ago

writea program to create a stack and do the following operations like push pop and peek and display the elements in the stack the stack should have attribues like name age department and salary​

Answers

Answered by rockingpankaj126
0

Answer:

class Stack:

#Constructor

def __init__(self):

self.stack = list()

self.maxSize = 8

self.top = 0

#Adds element to the Stack

def push(self,data):

if self.top>=self.maxSize:

return ("Stack Full!")

self.stack.append(data)

self.top += 1

return True

#Removes element from the stack

def pop(self):

if self.top<=0:

return ("Stack Empty!")

item = self.stack.pop()

self.top -= 1

return item

#Size of the stack

def size(self):

return self.top

Similar questions