From 0060538aa10d0320d152d2a0786ea329c4e3c882 Mon Sep 17 00:00:00 2001 From: ViolentAyang <76544389+ViolentAyang@users.noreply.github.com> Date: Thu, 14 Apr 2022 20:03:31 +0800 Subject: [PATCH] =?UTF-8?q?Create=20=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84?= =?UTF-8?q?=E9=93=BE=E5=BC=8F=E5=AD=98=E5=82=A8.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 树/二叉树的链式存储.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 树/二叉树的链式存储.c diff --git a/树/二叉树的链式存储.c b/树/二叉树的链式存储.c new file mode 100644 index 0000000..056320f --- /dev/null +++ b/树/二叉树的链式存储.c @@ -0,0 +1,31 @@ +#include +#include +#include + +typedef struct ElemType{ + int value; +}ElemType; + +typedef struct BiTNnode{ + ElemType data; + struct BiTNnode *lchild,*rchild;//左右孩子指针 + //struct BiTNnode *parent;//父节点指针 +}BiTNnode,*BiTree; + +int main(){ + //定义一棵树 + BiTree root = NULL; + //插入根结点 + root = (BiTree)malloc(sizeof(BiTNnode)); + root->data = {1}; + root->lchild = NULL; + root->rchild = NULL; + //插入新结点 + BiTNnode *p = (BiTree)malloc(sizeof(BiTNnode)); + p->data = {2}; + p->lchild = NULL; + p->rchild = NULL; + root->lchild = p; + return 0; +} +