您好,欢迎来到九壹网。
搜索
您的当前位置:首页数据结构二叉树的创建

数据结构二叉树的创建

来源:九壹网
typedef struct Node {

Datatype data;

struct Node *leftChild; struct Node *rightChild; }BiTreeNode;

void Initiate(BiTreeNode **root) {

*root = (BiTreeNode * )malloc(sizeof(BiTreeNode)); ( *root) -> leftChild = NULL; ( *root) -> rightChild = NULL; }

BiTreeNode *InsertLeftNode(BiTreeNode *curr,Datatype x) {

BiTreeNode *s, *t;

if(curr == NULL) return NULL;

t = curr -> leftChild;

s = (BiTreeNode * )malloc(sizeof(BiTreeNode)); s -> data = x; s -> leftChild = t;

s -> rightChild = NULL;

curr -> leftChild = s; return curr->leftChild; }

BiTreeNode *InsertRightNode(BiTreeNode *curr, Datatype x) {

BiTreeNode *s, *t;

if(curr == NULL) return NULL;

t = curr ->rightChild;

s = (BiTreeNode *)malloc(sizeof(BiTreeNode)); s -> data = x;

s -> rightChild = t; s -> leftChild = NULL;

curr -> rightChild = s; return curr -> rightChild;

}

BiTreeNode *DeleteLeftTree(BiTreeNode * curr) {

if(curr == NULL || curr -> leftChild == NULL) return NULL;

// Destroy(&curr -> leftChild); curr -> leftChild = NULL; return curr; }

BiTreeNode *DeleteRightTree(BiTreeNode *curr) {

if(curr == NULL || curr -> rightChild == NULL) return NULL;

// Destroy(&curr -> rightChild); curr -> rightChild = NULL; return curr; }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务