-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path01_stack_DS.py
More file actions
55 lines (43 loc) · 763 Bytes
/
01_stack_DS.py
File metadata and controls
55 lines (43 loc) · 763 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
48
49
50
51
52
53
'''
Stack Data structure
D
C
B
A
'''
class Stack():
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
if not self.is_empty():
return self.items.pop()
def is_empty(self):
return self.items == []
def peek(self):
if not self.is_empty():
return self.items[-1]
def get_Stack(self):
return self.items
s = Stack()
s.push("A")
s.push("B")
s.push("C")
s.push("D")
print(s.get_Stack())
s.pop()
print(s.get_Stack())
print(s.is_empty())
print(s.peek())
print("\n")
s2 = Stack()
s2.push(1)
s2.push(2)
s2.push(3)
s2.push(4)
print(s2.get_Stack())
s2.pop()
print(s2.get_Stack())
print(s2.peek())
print(s2.is_empty())