質問編集履歴
1
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,98 +1,6 @@
|
|
1
1
|
```ここに言語を入力
|
2
|
-
|
2
|
+
Node * BinaryTree::removeAll(Node *r) { //定義が不明....
|
3
|
-
using namespace std;
|
4
3
|
|
5
|
-
class Node {
|
6
|
-
friend class BinaryTree;
|
7
|
-
private:
|
8
|
-
int data;
|
9
|
-
Node *left;
|
10
|
-
Node *right;
|
11
|
-
public:
|
12
|
-
Node(int _data);
|
13
|
-
};
|
14
|
-
|
15
|
-
class BinaryTree {
|
16
|
-
private:
|
17
|
-
Node *root;
|
18
|
-
public:
|
19
|
-
BinaryTree();
|
20
|
-
~BinaryTree();
|
21
|
-
void insertNode(int d) { root = insertNode(root, d); }
|
22
|
-
Node *insertNode(Node *r, int d);
|
23
|
-
void printInorder() { printInorder(root); }
|
24
|
-
void printInorder(Node *r);
|
25
|
-
void printPreorder() { printPreorder(root); }
|
26
|
-
void printPreorder(Node *r);
|
27
|
-
void printPostorder() { printPostorder(root); }
|
28
|
-
void printPostorder(Node *r);
|
29
|
-
Node *removeAll( Node *r );
|
30
|
-
};
|
31
|
-
|
32
|
-
Node::Node(int _data) {
|
33
|
-
data = _data;
|
34
|
-
left = NULL;
|
35
|
-
right = NULL;
|
36
|
-
}
|
37
|
-
|
38
|
-
BinaryTree::BinaryTree() {
|
39
|
-
root = NULL;
|
40
|
-
};
|
41
|
-
|
42
|
-
BinaryTree::~BinaryTree( ) {
|
43
|
-
root = removeAll( root );
|
44
|
-
};
|
45
|
-
|
46
|
-
Node *BinaryTree::insertNode(Node *r, int d) {
|
47
|
-
|
48
|
-
if (root == NULL) {
|
49
|
-
root = new Node(d);
|
50
|
-
return root;
|
51
|
-
}
|
52
|
-
|
53
|
-
if (r->data == d)
|
54
|
-
return root;
|
55
|
-
|
56
|
-
if (r->data > d) {
|
57
|
-
if (r->left == NULL) {
|
58
|
-
r->left = new Node(d);
|
59
|
-
return root;
|
60
|
-
}
|
61
|
-
else
|
62
|
-
return insertNode(r->left, d);
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
|
66
|
-
if (r->right == NULL) {
|
67
|
-
r->right = new Node(d);
|
68
|
-
return root;
|
69
|
-
}
|
70
|
-
else
|
71
|
-
return insertNode(r->right, d);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
void BinaryTree::printPreorder(Node *r) {
|
76
|
-
|
77
|
-
if (r == NULL)
|
78
|
-
return;
|
79
|
-
cout << r->data << " ";
|
80
|
-
printPreorder(r->left);
|
81
|
-
printPreorder(r->right);
|
82
|
-
}
|
83
|
-
|
84
|
-
void BinaryTree::printInorder(Node *r) {
|
85
|
-
|
86
|
-
if (r == NULL)
|
87
|
-
return;
|
88
|
-
|
89
|
-
printInorder(r->left);
|
90
|
-
cout << r-> data << " ";
|
91
|
-
printInorder(r->right);
|
92
|
-
}
|
93
|
-
|
94
|
-
Node * BinaryTree::removeAll(Node *r) { //ここの定義が不明....
|
95
|
-
|
96
4
|
Node *removed;
|
97
5
|
if (root == NULL)
|
98
6
|
return NULL;
|