码迷,mamicode.com
首页 > 其他好文 > 详细

二叉树添加索引

时间:2017-08-22 23:10:03      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:thread   can   索引   return   str   scanf   scan   creat   size   

前序遍历创建,中序遍历添加索引。。

typedef struct BiNode
{
    char data;
    char ltag, rtag;
    struct BiNode *lchild, *rchild;
}BiNode;

void createTree(BiNode **root);
void printTree(BiNode *root, int lever);
void addThread(BiNode *root, BiNode *pre); 
void desTree(BiNode *root, BiNode *pre);

int main(int argc, char *argv[])
{
    BiNode *root = NULL;
    BiNode pre;
    BiNode *prePointer = ⪯ 
    int lever = 1;
    
    createTree(&root);
    printTree(root, lever);
    
    pre.ltag = t;
    pre.lchild = root;
    
    addThread(root, prePointer);
    
    pre.rtag = t;
    pre.rchild = prePointer;
    prePointer->rtag = t;
    prePointer->rchild = ⪯
    
    return 0;
}

void createTree(BiNode **root)
{
    char el;
    scanf("%c", &el);

    if(el ==  )
    {
        *root = NULL;
    }else {
        *root = (BiNode *)malloc(sizeof(BiNode));
        (*root)->data = el;
        (*root)->ltag = l;
        (*root)->rtag = l;
        
        createTree(&((*root)->lchild));
        createTree(&((*root)->rchild));
    }
}

void printTree(BiNode *root, int lever)
{
    if(root)
    {
        printf("data: %c, lever: %d \n", root->data, lever);
        printTree(root->lchild, lever+1);
        printTree(root->rchild, lever+1);
    }
}

void addThread(BiNode *root, BiNode *pre)
{
    if(root)
    {
        if(pre->rchild == NULL)
        {
            pre->rtag = t;
            pre->rchild = root;
        }
        if(root->lchild)
        {
            addThread(root->lchild, pre);
        }else {
            root->ltag = t;
            root->lchild = pre;
            pre = root->lchild;
        }
        
        pre = root;
        
        addThread(root->rchild, pre);
    }
}

void desTree(BiNode *root, BiNode *pre)
{
    
}

 

二叉树添加索引

标签:thread   can   索引   return   str   scanf   scan   creat   size   

原文地址:http://www.cnblogs.com/buerr/p/7413860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!