前序遍历(ABDECF):
typedef struct TreeNode { int data; struct TreeNode *left; struct TreeNode *right; struct TreeNode *parent; } TreeNode; void pre_order(TreeNode *Node) { if(Node != NULL) { printf("%d ", Node->data); pre_order(Node->left); pre_order(Node->right); } }
中序遍历(DBEAFC):
typedef struct TreeNode { int data; struct TreeNode *left; struct TreeNode *right; struct TreeNode *parent; } TreeNode; void middle_order(TreeNode *Node) { if(Node != NULL) { middle_order(Node->left); printf("%d ", Node->data); middle_order(Node->right); } }
后续遍历(DEBFCA):
typedef struct TreeNode { int data; struct TreeNode *left; struct TreeNode *right; struct TreeNode *parent; } TreeNode; void last_order(TreeNode *Node) { if(Node != NULL) { last_order(Node->left); last_order(Node->right); printf("%d ", Node->data); } }
3 total views, 3 views today