Cs refresher courses Northeastern University notes - tree algorithm

Binary Tree Binary linked list structure

typedef struct BiTNode {
    int data;
    struct BiTNode* lchild, * rchild;
} BiTNode, * BiTree;

Binary Tree Recursive template, the algorithm can solve most of the problem tree

BiTree func(BiTree T) {
    if(!T) {
        return NULL;
    }
     //do(T); 先序遍历
     T->lchild = func(T->lchild);
     //do(T); 中序遍历
     T->rchild = func(T->rchild);
    //do(T); 后序遍历
    return T;
}
  • First create a binary tree (recursive) preorder traversal way
  • The establishment of a binary tree (recursive) preorder way
  • Postorder way to create a binary tree (recursive)

Guess you like

Origin www.cnblogs.com/vergilwu/p/11668825.html