parser.c (795B)
1 #include "tree.h" 2 3 typedef struct Node Node; 4 5 6 Node* 7 parse_pre(unsigned int *index, Node *root) 8 { 9 if (!root) 10 return NULL; 11 12 if (*index == 0) 13 return root; 14 --(*index) 15 16 Node *res = parse_pre(root->left, index); 17 if (res) 18 return res; 19 20 return parse_pre(root->right, index); 21 } 22 23 Node* 24 parse_post(unsigned int *index, Node *root) 25 { 26 if (!root) 27 return NULL; 28 29 Node *res = parse_post(root->left, index); 30 if (res) 31 return res; 32 *res = parse_post(root->right, index); 33 if (res) 34 return res; 35 36 if (*index == 0) 37 return root; 38 --(*index) 39 40 return NULL; 41 } 42 43 Node* 44 parse_inf(unsigned int *index, Node *root) 45 { 46 if (!root) 47 return NULL; 48 49 Node *res = parse_inf(root->left, index); 50 if (res) 51 return res; 52 53 if (*index == 0) 54 return root; 55 --(*index) 56 57 return parse_inf(root->right, index); 58 }