回答編集履歴
1
append
test
CHANGED
@@ -33,3 +33,31 @@
|
|
33
33
|
root = gentree(root, list(f)) # ★str→listに変換
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
ちなみに`gentree`関数の第一引数には意味がないため、下記コードの方がすっきりしますね。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Python
|
44
|
+
|
45
|
+
def gentree(w):
|
46
|
+
|
47
|
+
p = tnode()
|
48
|
+
|
49
|
+
p.ope = w.pop()
|
50
|
+
|
51
|
+
if p.ope == "-" or p.ope == "+" or p.ope == "*" or p.ope == "/" :
|
52
|
+
|
53
|
+
p.right = gentree(w)
|
54
|
+
|
55
|
+
p.left = gentree(w)
|
56
|
+
|
57
|
+
return p
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
root = gentree(list(f))
|
62
|
+
|
63
|
+
```
|