首页 > 其他 > 详细

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

时间:2016-07-31 11:44:08      阅读:339      评论:0      收藏:0      [点我收藏+]
//树的链式存储--三叉表示法
#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");
}

技术分享

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

原文:http://www.cnblogs.com/zhanggaofeng/p/5722597.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!