-
Notifications
You must be signed in to change notification settings - Fork 0
/
usercase.py
executable file
·93 lines (82 loc) · 1.37 KB
/
usercase.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from Stack import Stack
from Queue import Queue
from BinaryTree import BinaryTree
def trrce(obj):
print(obj.info())
print("--------------Stack----------------")
s = Stack(5)
s.push(1)
trrce(s)
s.push(2)
trrce(s)
s.push(3)
trrce(s)
s.push(4)
trrce(s)
s.push(5)
trrce(s)
print("head = ", s.head())
print("tail = ", s.tail())
print("isFull? ", s.isFull())
s.pop()
trrce(s)
s.pop()
trrce(s)
s.pop()
trrce(s)
s.pop()
trrce(s)
s.pop()
trrce(s)
print("isEmpty? ",s.isEmpty())
print("--------------Queue----------------")
q = Queue(5)
q.add(1)
trrce(q)
q.add(2)
trrce(q)
q.add(3)
trrce(q)
q.add(4)
trrce(q)
q.add(5)
trrce(q)
print("first = ", q.first())
print("last = ", q.last())
print("isFull? ", q.isFull())
q.remove()
trrce(q)
q.remove()
trrce(q)
q.remove()
trrce(q)
q.remove()
trrce(q)
q.remove()
trrce(q)
print("isEmpty? ",s.isEmpty())
print("--------------BinaryTree----------------")
tree = '''
1
2 3
4 5
'''
print(tree)
r = BinaryTree() #root
rll = BinaryTree()
rll.makeTree(4,None,None)
rr = BinaryTree()
rr.makeTree(2,rll,None)
rrr = BinaryTree()
rrr.makeTree(5,None,None)
rl = BinaryTree()
rl.makeTree(3,None,rrr)
r.makeTree(1,rr,rl)
print("preOrder")
r.preOrder(r)
print("inOrder")
r.inOrder(r)
print("postOrder")
r.postOrder(r)
print("levelOrder")
r.levelOrder(r)