zoukankan      html  css  js  c++  java
  • 4.2 线索二叉树

    1. 创建

    #include <iostream>
    
    using namespace std;
    
    typedef struct node{
        dtype data;
        struct node *lchild;
        struct node *rchild;
        int ltag,rtag;
    }Node;
    
    typedef char dtype;
    
    //先序创建树
    void PreCreate(Node * &T){
        dtype ch;
        cin>>ch;
        if(ch=='#') T=NULL;
        else{
            T=new Node;
            T->data=ch;
            T->ltag=T->rtag=0;
            CreateTree(T->lchild);
            CreateTree(T->rchild);
        }
    }
    
    //中序创建树
    int InCreate(Node * &T){
        dtype ch;
        if (ch == "#") T = NULL;
        else {
            T=new Node;
            T->ltag = T->rtag=0;
            InCreate(T->lchild);
            T->data = ch;
            InCreate(T->rchild);
        }
    }
    
    //后序创建树
    int PostCreate(Node * &T, Node * &parent){
        dtype ch;
        if (ch == '#') T = NULL;
        else {
            T=new Node;
            T->parent = parent;
            T->ltag = T->rtag = 0;
            PostCreate(T->lchild, T);
            PostCreate(T->rchild, T);
            T->data = ch;
        }
    }
    
    int main(){
        
        return 0;
    }
  • 相关阅读:
    复变函数
    abc136
    点集
    一些数学题
    牛客多校第六场
    牛客多校第五场G
    复数
    generator 1
    digits 2
    Winner
  • 原文地址:https://www.cnblogs.com/Alexagender/p/10806328.html
Copyright © 2011-2022 走看看