当前位置:网站首页>Chain storage of binary tree

Chain storage of binary tree

2022-07-01 12:23:00 Between the steps

The sequential storage of binary tree is only suitable for complete binary tree and full binary tree , Chain storage is suitable for other ..

#include<stdio.h>

struct ElemType{
    
    int data;
};

typedef struct BiTNode{
    
    ElemType data;
    struct BiTNode *lchild,*rchild;     // Some may be added *parents  Trident linked list 
}BiTNode,*Bitree;

// Define an empty tree 
Bitree root=NULL;


// Insert root 
root=(Bitree)malloc(sizeof(BiTNode));
root->data={
    1};
root->lchild=NULL;
root->rchild=NULL;


// Insert new node 
BiTNode *p=(BiTNode*)malloc(sizeof(BiTNode));
p->data={
    2};
p->lchild=NULL;
p->rchild==NULL;
root->lchild=p;              // The left child as the root node 
原网站

版权声明
本文为[Between the steps]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207011204421531.html