-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1024.cpp
More file actions
87 lines (86 loc) · 1.1 KB
/
1024.cpp
File metadata and controls
87 lines (86 loc) · 1.1 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Filename: 1024.cpp
* Last modified: 2012-06-04 16:24
* Author: Chen Jiang(姜晨) -- [email protected]
* Description:
*/
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<iomanip>
#include<stdio.h>
using namespace std;
template<typename T>
class TN
{
public:
TN()
{
left=NULL;
right=NULL;
}
TN(T d, TN* l, TN* r)
{
data=d;
left=l;
right=r;
}
TN* left;
TN* right;
T data;
};
template<typename T>
class BT
{
public:
BT()
{
root=NULL;
}
TN<T>* root;
void insert(const T &d, TN* &t)
{
if(t==NULL)
t=new TN(d,NULL,NULL);
else if(d<t->data)
insert(d, t->left);
else if(d>t->data)
insert(d,t->right);
else
;
}
void insert(const T &d)
{
insert(d,root);
}
void print(TN* &t)
{
if(t==NULL)
;
else
{
cout<<t->data<<endl;
print(t->left);
print(t->right);
}
}
void print()
{
print(root);
}
};
int main()
{
BT<char> i;
i.insert('b');
i.insert('a');
i.insert('c');
i.insert('c');
i.print();
return 0;
}