-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1stack.py
More file actions
57 lines (51 loc) · 1.1 KB
/
1stack.py
File metadata and controls
57 lines (51 loc) · 1.1 KB
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
54
55
56
57
class Stack:
def __init__(self):
self.stack = list()
self.maxSize = 8
self.top = 0
def push(self,data):
if self.top>=self.maxSize:
return ("Stack Full!")
self.stack.append(data)
self.top += 1
return True
def pop(self):
if self.top<=0:
return ("Stack Empty!")
item = self.stack.pop()
self.top -= 1
return item
def size(self):
return self.top
def merge(a,b):
ans = []
while(len(a)>0):
ans.append(a.pop())
while(len(b)>0):
ans.append(b.pop())
return(ans)
a = [3,4]
b = [1,2]
m = merge(a,b)
for k in m:
print(k)
s = Stack()
print(s.push(1))
print(s.push(2))
print(s.push(3))
print(s.push(4))
print(s.push(5))
print(s.push(6))
print(s.push(7))
print(s.push(8))
print(s.push(9))
print(s.size())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.pop())