-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack-queue.py
49 lines (42 loc) · 1.04 KB
/
stack-queue.py
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
class stack:
def __init__(self):
self.storage=[]
self.count=0
def empty(self):
if (self.count==0):
return True
else:
return False
def store(self,x):
self.storage = self.storage + [x]
self.count = self.count + 1
return True
def retrieve(self):
if (self.count==0):
return [False,0]
else:
self.count = self.count - 1
rval = self.storage[-1]
self.storage = self.storage[0:-1]
return [True,rval]
class queue:
def __init__(self):
self.storage=[]
self.cnt = 0
def empty(self):
if self.cnt==0:
return True
else:
return False
def store(self,value):
self.storage=self.storage+[value]
self.cnt = self.cnt + 1
return self.cnt
def retrieve(self):
if (self.cnt==0):
return [False,0]
else:
r=self.storage[0]
self.cnt=self.cnt-1
self.storage=self.storage[1:]
return [True,r]