forked from dabeaz-course/practical-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataStruct.py
More file actions
54 lines (50 loc) · 1.01 KB
/
DataStruct.py
File metadata and controls
54 lines (50 loc) · 1.01 KB
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
50
51
52
53
'''
Write implementaton for
queue
stack
binary tree
'''
class TStack:
def __init__(self,tp,size):
self.top = tp
self.size =tp
self.Max=size
self.items =[]
def IsEmpty(self):
if(self.top ==-1):
return True
else:
return False
def IsFull(self):
if(self.top == self.Max):
return True
else:
return False
def Push(self,e):
self.top= self.top+1
self.items.append(e)
def Pop(self):
x = self.items.pop(self.top)
self.top = self.top-1
return x
st =TStack(-1,10)
st.Push(5)
st.Push(15)
st.Push(125)
st.Pop()
st.Push(51)
st.Push(152)
st.Push(0)
while(not st.IsEmpty()):
x1 = st.Pop()
print(x1)
class TQueue:
def __init__(self,sz):
self.front=-1
self.back = -1
self.len =sz
self.items=[]
def insert(self,e):
## dfs implementation for a simple graph -- with stack
## bfs implementation -- with queue
##