質問編集履歴
1
public StringBuilder rt = new StringBuilder("");をフィールドに追加した。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
public String expression; // このノードが表す式(二分木への分割後は演算子または項となる)
|
5
5
|
public Node left = null; // 左の子ノード
|
6
6
|
public Node right = null; // 右の子ノード
|
7
|
+
public StringBuilder rt = new StringBuilder("");
|
7
8
|
public String rt_expression; //後置記法の式
|
8
9
|
|
9
10
|
public void traversePostorder()
|
10
11
|
{
|
11
|
-
StringBuilder rt = new StringBuilder("");
|
12
12
|
// 左右に子ノードをもつ場合、表示する前にノードを再帰的に巡回する
|
13
13
|
if (left != null)
|
14
14
|
left.traversePostorder();
|
@@ -16,13 +16,17 @@
|
|
16
16
|
right.traversePostorder();
|
17
17
|
|
18
18
|
//rtにexpressionを追加していって後置記法の数式を完成させる
|
19
|
-
rt.append(expression);
|
19
|
+
this.rt.append(expression);
|
20
|
-
this.rt_expression = rt.toString();
|
21
20
|
// 巡回を終えた後でノードの演算子または項を表示する
|
22
21
|
// (読みやすさのために項の後に空白を補って表示する)
|
23
22
|
System.out.print(expression + " ");
|
24
23
|
}
|
25
24
|
|
25
|
+
public String getRtExpression() {
|
26
|
+
this.rt_expression = this.rt.toString();
|
27
|
+
return this.rt_expression;
|
28
|
+
}
|
29
|
+
|
26
30
|
}
|
27
31
|
```
|
28
32
|
|