Open bosthhe1 opened 1 year ago
中序 左子树 跟节点 右子树 void TestBinaryTree(BinaryTree *A) { if (A == NULL) { printf("NULL "); return; } TestBinaryTree(A->left); printf("%c ", A->a); TestBinaryTree(A->right);//就改了递归顺序 }
后序 左子树 右子树 跟节点 void TestBinaryTree(BinaryTree *A) { if (A == NULL) { printf("NULL "); return; } TestBinaryTree(A->left); TestBinaryTree(A->right);// printf("%c ", A->a); }
前序 跟节点 左子树 右子树 typedef char STDataType;
typedef struct BinaryTree { BinaryTree right; BinaryTree left; STDataType a; }BinaryTree;
void TestBinaryTree(BinaryTree *A) { if (A == NULL) {printf("NULL "); return;} printf("%c ", A->a); TestBinaryTree(A->left);//前序 TestBinaryTree(A->right);
} void TestBinaryTree1() { BinaryTree A = (BinaryTree )malloc(sizeof(BinaryTree)); A->a = 'A'; A->left = NULL; A->right = NULL; BinaryTree B = (BinaryTree )malloc(sizeof(BinaryTree)); B->a = 'B'; B->left = NULL; B->right = NULL; BinaryTree C = (BinaryTree )malloc(sizeof(BinaryTree)); C->a = 'C'; C->left = NULL; C->right = NULL; BinaryTree D = (BinaryTree )malloc(sizeof(BinaryTree)); D->a = 'D'; D->left = NULL; D->right = NULL; BinaryTree E = (BinaryTree )malloc(sizeof(BinaryTree)); E->a = 'E'; E->left = NULL; E->right = NULL; A->left = B; A->right = C; B->left = D; B->right = E; TestBinaryTree(A);
}
int main() { TestBinaryTree1(); return 0; }