- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStack.py
More file actions
Latest commit
45 lines (29 loc) · 811 Bytes
/
Copy pathArrayStack.py
File metadata and controls
45 lines (29 loc) · 811 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
classArrayStack:
def__init__(self):
self.data=[]
def__len__(self):
returnlen(self.data)
defis_empty(self):
returnlen(self.data) ==0
defpush(self,e):
self.data.append(e)
deftop(self):
ifself.is_empty():
returnNone
else:
returnself.data[-1]
defpop(self):
ifself.is_empty():
returnNone
else:
returnself.data.pop()
defreverse_file(filename):
S=ArrayStack()
original=open(filename)
forlineinoriginal:
S.push(line.rstrip("\n"))
original.close()
output=open(filename,"w")
whilenotS.is_empty():
output.write(S.pop() +"\n")
output.close()