-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackdoubling.py
More file actions
41 lines (34 loc) · 953 Bytes
/
Copy pathstackdoubling.py
File metadata and controls
41 lines (34 loc) · 953 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
class stack:
def __init__(self,limit=10):
self.stk = limit*[None]
self.limit = limit
self.index = 0
def isEmpty(self):
return self.stk <=0
def push(self,item):
if len(self.stk) >= self.limit:
self.resize()
self.stk.append(item)
print 'stack after push :',self.stk
self.index += 1
def pop():
if len(self.stk) <=0:
print "stack underflow"
else:
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)
def resize(self):
newstk = list(self.stk)
length = len(self.stk)
self.limit = 2*self.limit
self.stk = newstk
#for i in range(self.limit-length):
# self.stk.append(None)
s = stack(1)
map(s.push,range(100)) #pushing 1000 items