-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData Structure-Stack.py
More file actions
24 lines (19 loc) · 901 Bytes
/
Data Structure-Stack.py
File metadata and controls
24 lines (19 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
stack = []
def checkTheNumberOfElement(stack):
return len(stack)
def pushNewElement(newElement):
stack.append(newElement)
def popTheElement():
return stack.pop(len(stack)-1)#stack[len(stack)-1]
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
pushNewElement(1)
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
pushNewElement(3)
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
pushNewElement(5)
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
print("The toppest element is:", popTheElement())
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
print("The toppest element is:", popTheElement())
print("The number of elements in the stack is:", checkTheNumberOfElement(stack))
print("The toppest element is:", popTheElement())