-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8. Implement stack using array - v2.py
More file actions
60 lines (51 loc) · 1.26 KB
/
8. Implement stack using array - v2.py
File metadata and controls
60 lines (51 loc) · 1.26 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
58
59
60
#User function Template for python3
class MyStack:
def __init__(self):
self.arr=[]
#Function to push an integer into the stack.
def push(self,data):
#add code here
self.arr.append(data)
print(self.arr)
#Function to remove an item from top of the stack.
def pop(self):
#add code here
data = self.arr[1::]
self.arr = self.arr[1::]
print(self.arr)
print(data[0])
if not self.arr:
return -1
else:
return data[0]
"""
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__=='__main__':
t=int(input())
for i in range(t):
s=MyStack()
q=int(input())
q1=list(map(int,input().split()))
i=0
while(i<len(q1)):
if(q1[i]==1):
s.push(q1[i+1])
i=i+2
elif(q1[i]==2):
print(s.pop(),end=" ")
i=i+1
elif(s.isEmpty()):
print(-1)
i=i+1
print()
# } Driver Code Ends
"""
if __name__=='__main__':
s=MyStack()
s.push(2)
s.push(3)
s.pop()
s.push(4)
s.pop()