-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStacks.py
More file actions
47 lines (36 loc) · 856 Bytes
/
Stacks.py
File metadata and controls
47 lines (36 loc) · 856 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Node:
def __init__(self,data):
self.next = None
self.data = data
class Stacks:
## Linear data structures
## Flexible Size
## LIFO: Last In First Out
def __init__(self):
self.top = None
def isEmpty(self):
return self.tail==None
def peek(self):
return self.top.data
def push(self,data):
current = Node(data)
current.next = self.top
self.top = current
def pop(self):
if (self.top != None):
data = self.top.data
self.top = self.top.next
return data
def main():
a = Stacks()
a.push(1)
a.push(10)
a.push("Hi")
print (a.peek())
print (a.pop())
print (a.pop())
print (a.pop())
print (a.pop())
print (a.pop())
if __name__ == "__main__":
main()