File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,27 @@ class AVLTree : public BST <T, U>
54
54
return getValue (this ->root , key);
55
55
}
56
56
57
+
58
+ void printPreorder ()
59
+ {
60
+ preOrder (this ->root );
61
+ cout << endl;
62
+ }
63
+
64
+
65
+ void printInorder ()
66
+ {
67
+ inOrder (this ->root );
68
+ cout << endl;
69
+ }
70
+
71
+
72
+ void printPostorder ()
73
+ {
74
+ postOrder (this ->root );
75
+ cout << endl;
76
+ }
77
+
57
78
protected:
58
79
59
80
AVL_node <T, U>* root;
@@ -219,4 +240,34 @@ class AVLTree : public BST <T, U>
219
240
else if (n->key > key) return getValue (n->left , key);
220
241
else return n->value ;
221
242
}
243
+
244
+
245
+ void preOrder (AVL_node <T, U>* n)
246
+ {
247
+ if (n==NULL ) return ;
248
+
249
+ cout<<" (" <<n->key <<" ," <<n->value <<" ), " ;
250
+ preOrder (n->left );
251
+ preOrder (n->right );
252
+ }
253
+
254
+
255
+ void inOrder (AVL_node <T, U>* n)
256
+ {
257
+ if (n==NULL ) return ;
258
+
259
+ inOrder (n->left );
260
+ cout<<" (" <<n->key <<" ," <<n->value <<" ), " ;
261
+ inOrder (n->right );
262
+ }
263
+
264
+
265
+ void postOrder (AVL_node <T, U>* n)
266
+ {
267
+ if (n==NULL ) return ;
268
+
269
+ preOrder (n->left );
270
+ preOrder (n->right );
271
+ cout<<" (" <<n->key <<" ," <<n->value <<" ), " ;
272
+ }
222
273
};
You can’t perform that action at this time.
0 commit comments