質問編集履歴

1

文法の修正

2016/11/04 05:29

投稿

wanwanwan
wanwanwan

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,190 +1,6 @@
1
1
  ```ここに言語を入力
2
2
 
3
- #include <iostream>
4
-
5
- using namespace std;
6
-
7
-
8
-
9
- class Node {
10
-
11
- friend class BinaryTree;
12
-
13
- private:
14
-
15
- int data;
16
-
17
- Node *left;
18
-
19
- Node *right;
20
-
21
- public:
22
-
23
- Node(int _data);
24
-
25
- };
26
-
27
-
28
-
29
- class BinaryTree {
30
-
31
- private:
32
-
33
- Node *root;
34
-
35
- public:
36
-
37
- BinaryTree();
38
-
39
- ~BinaryTree();
40
-
41
- void insertNode(int d) { root = insertNode(root, d); }
42
-
43
- Node *insertNode(Node *r, int d);
44
-
45
- void printInorder() { printInorder(root); }
46
-
47
- void printInorder(Node *r);
48
-
49
- void printPreorder() { printPreorder(root); }
50
-
51
- void printPreorder(Node *r);
52
-
53
- void printPostorder() { printPostorder(root); }
54
-
55
- void printPostorder(Node *r);
56
-
57
- Node *removeAll( Node *r );
58
-
59
- };
60
-
61
-
62
-
63
- Node::Node(int _data) {
64
-
65
- data = _data;
66
-
67
- left = NULL;
68
-
69
- right = NULL;
70
-
71
- }
72
-
73
-
74
-
75
- BinaryTree::BinaryTree() {
76
-
77
- root = NULL;
78
-
79
- };
80
-
81
-
82
-
83
- BinaryTree::~BinaryTree( ) {
84
-
85
- root = removeAll( root );
86
-
87
- };
88
-
89
-
90
-
91
- Node *BinaryTree::insertNode(Node *r, int d) {
92
-
93
-
94
-
95
- if (root == NULL) {
96
-
97
- root = new Node(d);
98
-
99
- return root;
100
-
101
- }
102
-
103
-
104
-
105
- if (r->data == d)
106
-
107
- return root;
108
-
109
-
110
-
111
- if (r->data > d) {
112
-
113
- if (r->left == NULL) {
114
-
115
- r->left = new Node(d);
116
-
117
- return root;
118
-
119
- }
120
-
121
- else
122
-
123
- return insertNode(r->left, d);
124
-
125
- }
126
-
127
- else {
128
-
129
-
130
-
131
- if (r->right == NULL) {
132
-
133
- r->right = new Node(d);
134
-
135
- return root;
136
-
137
- }
138
-
139
- else
140
-
141
- return insertNode(r->right, d);
142
-
143
- }
144
-
145
- }
146
-
147
-
148
-
149
- void BinaryTree::printPreorder(Node *r) {
150
-
151
-
152
-
153
- if (r == NULL)
154
-
155
- return;
156
-
157
- cout << r->data << " ";
158
-
159
- printPreorder(r->left);
160
-
161
- printPreorder(r->right);
162
-
163
- }
164
-
165
-
166
-
167
- void BinaryTree::printInorder(Node *r) {
168
-
169
-
170
-
171
- if (r == NULL)
172
-
173
- return;
174
-
175
-
176
-
177
- printInorder(r->left);
178
-
179
- cout << r-> data << " ";
180
-
181
- printInorder(r->right);
182
-
183
- }
184
-
185
-
186
-
187
- Node * BinaryTree::removeAll(Node *r) { //ここの定義が不明....
3
+ Node * BinaryTree::removeAll(Node *r) { //定義が不明....
188
4
 
189
5
 
190
6