-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
33 lines (27 loc) · 764 Bytes
/
Copy pathstack.py
File metadata and controls
33 lines (27 loc) · 764 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
class stack:
def __init__(self,limit=10):
self.stk = []
self.limit = limit
def isEmpty(self):
return len(self.stk) <=0
def push(self,item):
if len(self.stk) >= self.limit:
print "stack overflow"
else:
self.stk.append(item)
#print 'stack after push :',self.stk
def pop():
if len(self.stk) <=0:
print "stack underflow"
else:
return self.stk.pop()
def peek(self):
if len(stk) <=0:
print "stack underflow"
else:
return self.stk[-1]
def size(self):
return len(self.stk)
if __name__ == "__main__":
s = stack(100000000)
map(s.push,range(100000000)) #pushing 1000 items