标签:turn char child nbsp ace struct code 数组 typedef
1 #include <iostream> 2 #include <stdlib.h> 3 #include <string> 4 #include <cstring> 5 #include <algorithm> 6 #include <cstdio> 7 using namespace std; 8 9 typedef struct node; 10 typedef node *tree; 11 struct node 12 { 13 char data; 14 tree lchild, rchild; 15 }; 16 tree bt; 17 18 int i; 19 string s; 20 21 void build(tree &bt) //建树 22 { 23 if(s[++i]!=‘.‘) 24 { 25 bt = new node; 26 bt = new node; 27 bt->data = s[i]; 28 build(bt->lchild); 29 build(bt->rchild); 30 } 31 else bt = NULL; 32 } 33 void printzx(tree bt) //输出中序序列 34 { 35 if(bt) 36 { 37 printzx(bt->lchild); 38 cout << bt->data; 39 printzx(bt->rchild); 40 } 41 } 42 void printhx(tree bt) //输出后序序列 43 { 44 if(bt) 45 { 46 printhx(bt->lchild); 47 printhx(bt->rchild); 48 cout << bt->data; 49 } 50 } 51 int main() 52 { 53 cin >> s; 54 i = -1; 55 build(bt); 56 printzx(bt); 57 cout << endl; 58 printhx(bt); 59 cout << endl; 60 return 0; 61 }
标签:turn char child nbsp ace struct code 数组 typedef
原文地址:https://www.cnblogs.com/ljy-endl/p/11260494.html