質問編集履歴
2
コードがあやまっていたため
test
CHANGED
File without changes
|
test
CHANGED
@@ -272,7 +272,7 @@
|
|
272
272
|
|
273
273
|
char c;
|
274
274
|
|
275
|
-
char
|
275
|
+
char str[100];
|
276
276
|
|
277
277
|
node *p;
|
278
278
|
|
1
解決したさいのコードを追記したため
test
CHANGED
File without changes
|
test
CHANGED
@@ -231,3 +231,163 @@
|
|
231
231
|
|
232
232
|
|
233
233
|
```
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
###追記
|
240
|
+
|
241
|
+
解決時のコード
|
242
|
+
|
243
|
+
```
|
244
|
+
|
245
|
+
#include<stdio.h>
|
246
|
+
|
247
|
+
#include<stdlib.h>
|
248
|
+
|
249
|
+
#include<string.h>
|
250
|
+
|
251
|
+
#include<ctype.h>
|
252
|
+
|
253
|
+
#include<math.h>
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
struct node{
|
258
|
+
|
259
|
+
char oper[10];
|
260
|
+
|
261
|
+
struct node *left;
|
262
|
+
|
263
|
+
struct node *right;
|
264
|
+
|
265
|
+
};
|
266
|
+
|
267
|
+
typedef struct node node;
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
node *bin_tree(){
|
272
|
+
|
273
|
+
char c;
|
274
|
+
|
275
|
+
char w[100],str[100];
|
276
|
+
|
277
|
+
node *p;
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
while((c = getchar()) != EOF){
|
282
|
+
|
283
|
+
if(c != ' '){
|
284
|
+
|
285
|
+
ungetc(c,stdin);
|
286
|
+
|
287
|
+
scanf("%s" , str);
|
288
|
+
|
289
|
+
p = (node *)malloc(sizeof(node));
|
290
|
+
|
291
|
+
strcpy(p->oper , str);
|
292
|
+
|
293
|
+
if(isdigit(c) != 0){
|
294
|
+
|
295
|
+
p->left = NULL;
|
296
|
+
|
297
|
+
p->right = NULL;
|
298
|
+
|
299
|
+
return p;
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
else{
|
304
|
+
|
305
|
+
p->left = bin_tree();
|
306
|
+
|
307
|
+
p->right = bin_tree();
|
308
|
+
|
309
|
+
return p;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
return 0;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
void inorder(node *p){
|
324
|
+
|
325
|
+
if(p == NULL){
|
326
|
+
|
327
|
+
return ;
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
else{
|
332
|
+
|
333
|
+
inorder(p->left);
|
334
|
+
|
335
|
+
printf("%s " , p->oper);
|
336
|
+
|
337
|
+
inorder(p->right);
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
void postorder(node *p){
|
346
|
+
|
347
|
+
if(p == NULL){
|
348
|
+
|
349
|
+
return ;
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
else{
|
354
|
+
|
355
|
+
postorder(p->left);
|
356
|
+
|
357
|
+
postorder(p->right);
|
358
|
+
|
359
|
+
printf("%s " , p->oper);
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
int main(void){
|
368
|
+
|
369
|
+
node *root = NULL;
|
370
|
+
|
371
|
+
root = bin_tree();
|
372
|
+
|
373
|
+
printf("infix notation ====> ");
|
374
|
+
|
375
|
+
inorder(root);
|
376
|
+
|
377
|
+
printf("\n");
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
printf("postifx notation ==> ");
|
382
|
+
|
383
|
+
postorder(root);
|
384
|
+
|
385
|
+
printf("\n");
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
return 0;
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
```
|