mirror of
https://github.com/ViolentAyang/DataStructureC.git
synced 2026-02-02 18:10:59 +08:00
Create 二叉树的链式存储.c
This commit is contained in:
31
树/二叉树的链式存储.c
Normal file
31
树/二叉树的链式存储.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdbool.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user