0% found this document useful (0 votes)
10 views1 page

Array Implementation of Stack

LAB Program

Uploaded by

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

Array Implementation of Stack

LAB Program

Uploaded by

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

class Stack:

def __init__(self):
self.top = -1
self.size = 1000
self.arr = [0] * self.size

def push(self, x):


self.top += 1
self.arr[self.top] = x

def pop(self):
x = self.arr[self.top]
self.top -= 1
return x
def display(self):
for i in range (self.top,-1,-1):
print(self.arr[i])

def Top(self):
return self.arr[self.top]

def Size(self):
return self.top + 1

if __name__ == "__main__":
s = Stack()
s.push(6)
s.push(3)
s.push(7)
s.display()
print("Top of stack is before deleting any element", s.Top())
print("Size of stack before deleting any element", s.Size())
print("The element deleted is", s.pop())
print("Size of stack after deleting an element", s.Size())
print("Top of stack after deleting an element", s.Top())

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy