質問編集履歴
2
コードがあやまっていたため
title
CHANGED
File without changes
|
body
CHANGED
@@ -135,7 +135,7 @@
|
|
135
135
|
|
136
136
|
node *bin_tree(){
|
137
137
|
char c;
|
138
|
-
char
|
138
|
+
char str[100];
|
139
139
|
node *p;
|
140
140
|
|
141
141
|
while((c = getchar()) != EOF){
|
1
解決したさいのコードを追記したため
title
CHANGED
File without changes
|
body
CHANGED
@@ -114,4 +114,84 @@
|
|
114
114
|
return 0;
|
115
115
|
}
|
116
116
|
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
###追記
|
121
|
+
解決時のコード
|
122
|
+
```
|
123
|
+
#include<stdio.h>
|
124
|
+
#include<stdlib.h>
|
125
|
+
#include<string.h>
|
126
|
+
#include<ctype.h>
|
127
|
+
#include<math.h>
|
128
|
+
|
129
|
+
struct node{
|
130
|
+
char oper[10];
|
131
|
+
struct node *left;
|
132
|
+
struct node *right;
|
133
|
+
};
|
134
|
+
typedef struct node node;
|
135
|
+
|
136
|
+
node *bin_tree(){
|
137
|
+
char c;
|
138
|
+
char w[100],str[100];
|
139
|
+
node *p;
|
140
|
+
|
141
|
+
while((c = getchar()) != EOF){
|
142
|
+
if(c != ' '){
|
143
|
+
ungetc(c,stdin);
|
144
|
+
scanf("%s" , str);
|
145
|
+
p = (node *)malloc(sizeof(node));
|
146
|
+
strcpy(p->oper , str);
|
147
|
+
if(isdigit(c) != 0){
|
148
|
+
p->left = NULL;
|
149
|
+
p->right = NULL;
|
150
|
+
return p;
|
151
|
+
}
|
152
|
+
else{
|
153
|
+
p->left = bin_tree();
|
154
|
+
p->right = bin_tree();
|
155
|
+
return p;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
return 0;
|
160
|
+
}
|
161
|
+
|
162
|
+
void inorder(node *p){
|
163
|
+
if(p == NULL){
|
164
|
+
return ;
|
165
|
+
}
|
166
|
+
else{
|
167
|
+
inorder(p->left);
|
168
|
+
printf("%s " , p->oper);
|
169
|
+
inorder(p->right);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
void postorder(node *p){
|
174
|
+
if(p == NULL){
|
175
|
+
return ;
|
176
|
+
}
|
177
|
+
else{
|
178
|
+
postorder(p->left);
|
179
|
+
postorder(p->right);
|
180
|
+
printf("%s " , p->oper);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
int main(void){
|
185
|
+
node *root = NULL;
|
186
|
+
root = bin_tree();
|
187
|
+
printf("infix notation ====> ");
|
188
|
+
inorder(root);
|
189
|
+
printf("\n");
|
190
|
+
|
191
|
+
printf("postifx notation ==> ");
|
192
|
+
postorder(root);
|
193
|
+
printf("\n");
|
194
|
+
|
195
|
+
return 0;
|
196
|
+
}
|
117
197
|
```
|