-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbintree.cpp
More file actions
63 lines (47 loc) · 1.08 KB
/
bintree.cpp
File metadata and controls
63 lines (47 loc) · 1.08 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
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include "bintree.h"
using namespace std;
template <typename T>
class Printint
{
public:
void operator()(T e) { cout << e << " "; }
};
int main()
{
BinTree<int> * bt1 = new BinTree<int>(new BinNode<int>(5, NULL));
bt1->insertAsLC(bt1->root(), 2);
bt1->insertAsRC(bt1->root(), 3);
BinTree<int> * bt = new BinTree<int>(new BinNode<int>(9, NULL));
bt->insertAsLC(bt->root(), 7);
bt->insertAsRC(bt->root(), 8);
bt->attachAsLC(bt->root()->lchild, bt1);
Printint<int> visit;
(bt->root())->travPre_I(visit);
cout << endl;
(bt->root())->travPre_II(visit);
cout << endl;
(bt->root())->travPre_R(visit);
cout << endl << endl;
(bt->root())->travIn_R(visit);
cout << endl;
(bt->root())->travIn_I(visit);
cout << endl;
auto x = bt->root();
while (x->lchild != NULL)
x = x->lchild;
while (x != NULL)
{
cout << x->data << " ";
x = x->succ();
}
cout << endl << endl;
(bt->root())->travPost_R(visit);
cout << endl;
(bt->root())->travPost_I(visit);
cout << endl << endl;
(bt->root())->travLevel(visit);
cout << endl;
bt->display();
return 0;
}