bosthhe1 / -

数据结构与算法(初阶)
0 stars 0 forks source link

二叉树 #10

Open bosthhe1 opened 1 year ago

bosthhe1 commented 1 year ago

前序 跟节点 左子树 右子树 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; } G@UG1 J~C~4Z_93B00)2OL3

bosthhe1 commented 1 year ago

中序 左子树 跟节点 右子树 void TestBinaryTree(BinaryTree *A) { if (A == NULL) { printf("NULL "); return; } TestBinaryTree(A->left); printf("%c ", A->a); TestBinaryTree(A->right);//就改了递归顺序 } DD@ BZZ0X MKN%BR7ZG9 {4

bosthhe1 commented 1 year ago

后序 左子树 右子树 跟节点 void TestBinaryTree(BinaryTree *A) { if (A == NULL) { printf("NULL "); return; } TestBinaryTree(A->left); TestBinaryTree(A->right);// printf("%c ", A->a); } RUGJ`J3(2%1496~)BYY{4(7