数据结构 树的链式存储(三叉表示法)

//树的链式存储--三叉表示法
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct _TreeNode{
    //数据域
    int data;
    //指针域
    struct _TreeNode * leftchild;//左孩子指针
    struct _TreeNode * rightchild;//右孩子指针
    struct _TreeNode * parent;//双亲指针---比二叉表示法多了一个双亲指针
}TreeNode, *TreeNodePointer;

void Test1(){
    //定义结构体对象
    TreeNode t1, t2, t3, t4, t5;
    //填充数据域
    t1.data = 1;
    t2.data = 2;
    t3.data = 3;
    t4.data = 4;
    t5.data = 5;

    //建立树之间的关系
    //t1是根节点  t2是t1的左孩子
    t1.leftchild = &t2;
    t1.rightchild = NULL;
    t1.parent = NULL;

    // t3是t2的左孩子
    t2.leftchild = &t3;
    t2.rightchild = NULL;
    t2.parent = &t1;

    // t4是t2的左孩子
    t3.leftchild = &t4;
    t3.rightchild = NULL;
    t3.parent = &t2;

    // t5是t4的左孩子
    t4.leftchild = &t5;
    t4.rightchild = NULL;
    t4.parent = &t2;

    //t5没有孩子节点
    t5.leftchild = NULL;
    t5.rightchild = NULL;
    t5.parent = &t4;
}

void main(){
    
    system("pause");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值