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

Class Stack

Uploaded by

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

Class Stack

Uploaded by

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

class Stack:

def __init__(self):
[Link] = []

def is_empty(self):
return [Link] == []

def push(self, item):


[Link](item)

def pop(self):
if not self.is_empty():
return [Link]()
else:
print("Stack is empty")

def peek(self):
if not self.is_empty():
return [Link][-1]
else:
print("Stack is empty")

def size(self):
return len([Link])

# Example usage:
stack = Stack()

[Link](1)
[Link](2)
[Link](3)

print("Stack size:", [Link]()) # Output: 3


print("Top element:", [Link]()) # Output: 3

print("Popping elements:")
print([Link]()) # Output: 3
print([Link]()) # Output: 2
print([Link]()) # Output: 1

print("Stack size after popping:", [Link]()) # Output: 0

You might also like