Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a17afa

Browse files
Add files via upload
1 parent cbb0085 commit 2a17afa

File tree

4 files changed

+857
-0
lines changed

4 files changed

+857
-0
lines changed

‎AVLShell.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
2+
Type "help", "copyright", "credits" or "license()" for more information.
3+
>>>
4+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
5+
>>> bst = BST()
6+
>>> bst.insert(None, 3)
7+
<__main__.Node object at 0x04169A10>
8+
>>> bst.root
9+
Traceback (most recent call last):
10+
File "<pyshell#2>", line 1, in <module>
11+
bst.root
12+
AttributeError: 'BST' object has no attribute 'root'
13+
>>>
14+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
15+
>>> avl = AVLTree()
16+
>>> root = None
17+
>>> root = avl.insert(root, 13)
18+
>>> root.val
19+
13
20+
>>> root.height
21+
0
22+
>>> avl.insert(root, 10)
23+
<__main__.Node object at 0x039699F0>
24+
>>> avl.insert(root, 15)
25+
<__main__.Node object at 0x039699F0>
26+
>>> avl.insert(root, 16)
27+
<__main__.Node object at 0x039699F0>
28+
>>> root.left.val
29+
10
30+
>>> root.left.left.val
31+
Traceback (most recent call last):
32+
File "<pyshell#12>", line 1, in <module>
33+
root.left.left.val
34+
AttributeError: 'NoneType' object has no attribute 'val'
35+
>>> root.left.height
36+
0
37+
>>> root.height
38+
2
39+
>>> root.right.val
40+
15
41+
>>> avl.inorder(root)
42+
10 0
43+
13 2
44+
15 1
45+
16 0
46+
>>>
47+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
48+
>>> avl = AVLTree()
49+
>>> root = None
50+
>>> root = avl.insert(root, 13)
51+
>>> root.balance
52+
0
53+
>>> avl.insert(root, 10)
54+
<__main__.Node object at 0x03AE7E50>
55+
>>> root.balance
56+
1
57+
>>> root.left.balance
58+
0
59+
>>> avl.insert(root, 15)
60+
<__main__.Node object at 0x03AE7E50>
61+
>>> avl.insert(root, 16)
62+
<__main__.Node object at 0x03AE7E50>
63+
>>> root.right.balance
64+
-1
65+
>>> root.right.right.balance
66+
0
67+
>>> root.balance
68+
-1
69+
>>> root.left.balance
70+
0
71+
>>> root.height
72+
2
73+
>>> root.right.height
74+
1
75+
>>> root.right.right.height
76+
0
77+
>>>
78+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
79+
>>> avl = AVLTree()
80+
>>> root = avl.insert(None, 30)
81+
>>> root = avl.insert(None, 10)
82+
>>> root = avl.insert(root, 20)
83+
>>> root = avl.insert(root, 30)
84+
>>> root = avl.insert(root, 40)
85+
>>> root = avl.insert(root, 50)
86+
>>> avl.inorder(root)
87+
10 2
88+
20 3
89+
30 2
90+
40 1
91+
50 0
92+
>>> root = avl.insert(root, 25)
93+
>>> avl.inorder(root)
94+
10 2
95+
20 3
96+
25 0
97+
30 1
98+
40 2
99+
50 0
100+
>>>
101+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
102+
>>> avl = AVLTree()
103+
>>> root = avl.insert(None, 30)
104+
>>> root = avl.insert(None, 10)
105+
>>> root = avl.insert(root, 20)
106+
>>> root = avl.insert(root, 30)
107+
>>> root = avl.insert(root, 40)
108+
>>> root = avl.insert(root, 50)
109+
>>> avl.inorder(root)
110+
10 0 -2
111+
20 4 -4
112+
30 3 -2
113+
40 4 -1
114+
50 0 0
115+
>>> root.val
116+
40
117+
>>> root.left.val
118+
20
119+
>>> root.left.left.val
120+
10
121+
>>> root.left.right.val
122+
30
123+
>>> root.right.val
124+
50
125+
>>>
126+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
127+
>>> avl = AVLTree()
128+
>>> root = avl.insert(None, 10)
129+
>>> root = avl.insert(root, 20)
130+
>>> root = avl.insert(root, 30)
131+
>>> root = avl.insert(root, 40)
132+
>>> root = avl.insert(root, 50)
133+
>>> avl.inorder(root)
134+
10 0 -2
135+
20 2 -1
136+
30 0 -2
137+
40 1 -1
138+
50 0 0
139+
>>> root.val
140+
20
141+
>>> root.right.val
142+
40
143+
>>>
144+
============== RESTART: G:/ProgramsPython/Algorithms/AVLTree.py ==============
145+
>>> avl = AVLTree()
146+
>>> root = avl.insert(None, 10)
147+
>>> root = avl.insert(root, 20)
148+
>>> root = avl.insert(root, 30)
149+
>>> root = avl.insert(root, 40)
150+
>>> root = avl.insert(root, 50)
151+
>>> avl.inorder(root)
152+
10 0 0
153+
20 2 -1
154+
30 0 0
155+
40 1 0
156+
50 0 0
157+
>>> root = avl.insert(root, 25)
158+
>>> avl.inorder(root)
159+
10 0 0
160+
20 2 -1
161+
25 0 0
162+
30 1 1
163+
40 3 2
164+
50 0 0
165+
>>> root.val
166+
40
167+
>>> root.left.val
168+
20
169+
>>> root.right.val
170+
50
171+
>>> root.left.right.val
172+
30
173+
>>> root.left.left.val
174+
10
175+
>>> root.left.right.left
176+
<__main__.Node object at 0x035E7F70>
177+
>>> root.left.right.left.val
178+
25
179+
>>>

‎AVLShell2.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
2+
Type "help", "copyright", "credits" or "license()" for more information.
3+
>>>
4+
============== RESTART: G:\ProgramsPython\Algorithms\AVLTree.py ==============
5+
>>> avl = AVLTree()
6+
>>> root = None
7+
>>> root = avl.insert(root, 10)
8+
>>> root.val
9+
10
10+
>>> root
11+
<__main__.Node object at 0x03DBD5D0>
12+
>>> root.height
13+
0
14+
>>> root.balance
15+
0
16+
>>> root.left
17+
>>> root = avl.insert(root, 20)
18+
>>> root.val
19+
10
20+
>>> root
21+
<__main__.Node object at 0x03DBD5D0>
22+
>>> root.height
23+
1
24+
>>> root.balance
25+
-1
26+
>>> root.right.val
27+
20
28+
>>> root.right.height
29+
0
30+
>>> root.right.balance
31+
0
32+
>>> root = avl.insert(root, 30)
33+
>>> root.height
34+
1
35+
>>> root.val
36+
20
37+
>>> root.balance
38+
0
39+
>>> root.right.val
40+
30
41+
>>> root.right.height
42+
0
43+
>>> root.right.balance
44+
0
45+
>>> print(root.left.val, root.left.height,
46+
root.left.balance)
47+
10 0 0
48+
>>> root = avl.insert(root, 40)
49+
>>> print(root.val, root.height, root.balance)
50+
20 2 -1
51+
>>> print(root.left.val, root.left.height,
52+
root.left.balance)
53+
10 0 0
54+
>>> print(root.right.val, root.right.height,
55+
root.right.balance)
56+
30 1 -1
57+
>>> print(root.right.right.val,
58+
root.right.right.height,
59+
root.right.right.balance)
60+
40 0 0
61+
>>> root = avl.insert(root, 40)
62+
>>> avl.inorder(root)
63+
10 0 0
64+
20 2 -1
65+
30 0 0
66+
40 1 0
67+
40 0 0
68+
>>> avl2 = AVLTree()
69+
>>> root2 = None
70+
>>> root2 = avl2.insert(root2, 10)
71+
>>> root2 = avl2.insert(root2, 20)
72+
>>> root2 = avl2.insert(root2, 30)
73+
>>> root2 = avl2.insert(root2, 40)
74+
>>> root2 = avl2.insert(root2, 50)
75+
>>> avl2.inorder(root2)
76+
10 0 0
77+
20 2 -1
78+
30 0 0
79+
40 1 0
80+
50 0 0
81+
>>> print(root.val, root.height, root.balance)
82+
20 2 -1
83+
>>> print(root2.val, root2.height, root2.balance)
84+
20 2 -1
85+
>>> print(root2.right.val,
86+
root2.right.height,
87+
root2.right.balance)
88+
40 1 0
89+
>>> print(root2.right.right.val,
90+
root2.right.right.height,
91+
root2.right.right.balance)
92+
50 0 0
93+
>>> print(root2.right.left.val,
94+
root2.right.left.height,
95+
root2.right.left.balance)
96+
30 0 0
97+
>>> print(root2.left.val,
98+
root2.left.height,
99+
root2.left.balance)
100+
10 0 0
101+
>>> root2 = avl2.insert(root2, 25)
102+
>>> avl2.inorder(root2)
103+
10 0 0
104+
20 2 -1
105+
25 0 0
106+
30 1 1
107+
40 3 2
108+
50 0 0
109+
>>> print(root2.val, root2.height, root2.balance)
110+
40 3 2
111+
>>>
112+
============== RESTART: G:\ProgramsPython\Algorithms\AVLTree.py ==============
113+
>>> avl = AVLTree()
114+
>>> root = None
115+
>>> root = avl.insert(root, 10)
116+
>>> root = avl.insert(root, 20)
117+
>>> root = avl.insert(root, 30)
118+
>>> root = avl.insert(root, 40)
119+
>>> root = avl.insert(root, 50)
120+
>>> root = avl.insert(root, 25)
121+
122+
>>> avl.inorder(root)
123+
10 0 0
124+
20 1 0
125+
25 0 0
126+
30 2 0
127+
40 1 -1
128+
50 0 0
129+
>>> print(root.val, root.height, root.balance)
130+
30 2 0
131+
>>>
132+
============== RESTART: G:\ProgramsPython\Algorithms\AVLTree.py ==============
133+
>>>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /