-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_2.py
More file actions
37 lines (29 loc) · 790 Bytes
/
Stack_2.py
File metadata and controls
37 lines (29 loc) · 790 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
class Stack:
def __init__(self):
self.data = []
def append(self,data):
self.data.append(data)
def remove(self):
self.data.pop(-1)
def top_stack(self):
print(self.data[-1])
def count(self):
print("count:" + str(len(self.data)))
def reverse_stack(self):
temp_stack = []
for i in range(len(self.data)):
temp = self.data.pop()
temp_stack.append(temp)
for i in range(len(temp_stack)):
temp = temp_stack.pop(0)
self.data.append(temp)
def print_stack(self):
print(self.data)
s = Stack()
s.append(10)
s.append(15)
s.append(30)
s.reverse_stack()
s.print_stack()
#s.top_stack()
#s.count()