博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BST(binary search tree)类型题目需要用到的头文件binary_tree.h
阅读量:4185 次
发布时间:2019-05-26

本文共 1534 字,大约阅读时间需要 5 分钟。

下面是二叉搜索树需要用到的头文件binary_tree.h

#include 
struct BinaryTreeNode{ int value; BinaryTreeNode* pLeft; BinaryTreeNode* pRight;};BinaryTreeNode* CreateBinaryTreeNode(int value){ BinaryTreeNode* pNode = new BinaryTreeNode(); pNode->value = value; pNode->pLeft = NULL; pNode->pRight = NULL; return pNode;}void ConnectTreeNodes(BinaryTreeNode* pParent, BinaryTreeNode* pLeft, BinaryTreeNode* pRight){ if(pParent != NULL){ pParent->pLeft = pLeft; pParent->pRight = pRight; }}void PrintTreeNode(BinaryTreeNode* pNode){ if(pNode != NULL){ printf("value of this node is: %d\n ", pNode->value); if(pNode->pLeft != NULL) printf("value of its left child is: %d \n", pNode->pLeft->value); else printf("left child is null. \n"); if(pNode->pRight != NULL) printf("value of its right child is: %d \n", pNode->pRight->value); else printf("right child is null. \n"); }else{ printf("this node is null. \n"); } printf("\n");}void PrintTree(BinaryTreeNode* pRoot){ PrintTreeNode(pRoot); if(pRoot != NULL){ if(pRoot->pLeft != NULL) PrintTree(pRoot->pLeft); if(pRoot->pRight != NULL) PrintTree(pRoot->pRight); }}void DestroyTree(BinaryTreeNode* pRoot){ if(pRoot != NULL){ BinaryTreeNode* pLeft = pRoot->pLeft; BinaryTreeNode* pRight = pRoot->pRight; delete pRoot; pRoot = NULL; DestroyTree(pLeft); DestroyTree(pRight); }}

转载地址:http://ozcoi.baihongyu.com/

你可能感兴趣的文章
Shell命令的随记
查看>>
TCP,HTTP,WEBSOCKET随记
查看>>
关于JVM内存区域的组成以及堆内存的回收原理
查看>>
JVM的垃圾回收机制以及回收策略随记
查看>>
生成XML的方法
查看>>
Reactor模式
查看>>
Connector configured to listen on port 8080 failed to start
查看>>
注解的使用
查看>>
【转】inet_addr、inet_aton、inet_pton异同小结
查看>>
linux中绑定80端口失败
查看>>
关于链接失败 对xxxx ‘__gxx_personality_v0’未定义的引用
查看>>
关于char*类型返回值和字符串常量
查看>>
epoll的一些关键点和总结(一)
查看>>
epoll的一些关键点和总结(二)
查看>>
关于epoll边缘触发模式(ET)下的EPOLLOUT触发
查看>>
socket TCP编程中connect的一些坑
查看>>
从C++单例模式到线程安全
查看>>
浅谈C文件编译过程
查看>>
FOJ 1001之位图数据结构对程序的优化
查看>>
盛名之下,其实难副?——再读CMU巨著CSAPP
查看>>