关于数据结构的学习经验分享 (二叉树相关的内容)
来源:互联网 发布:手机看片下什么软件 编辑:程序博客网 时间:2024/05/17 01:06
本文主要关于二叉树的相关内容,
首先描述了二叉树相关的基本代码,然后总结了二叉树基本的知识,最后概述了二叉树相关的题目的总结
1.二叉树基本数据结构描述
struct BinaryTreeNode //定义了二叉树节点信息{ int m_nValue; //二叉树的节点数据 BinaryTreeNode* m_pLeft; //左边指针 BinaryTreeNode* m_pRight; //右边指针};BinaryTreeNode* CreateBinaryTreeNode(int value); //创建二叉树节点void ConnectTreeNodes(BinaryTreeNode* pParent, BinaryTreeNode* pLeft, BinaryTreeNode* pRight); //链接二叉树节点 void PrintTreeNode(BinaryTreeNode* pNode); //打印二叉树节点 void PrintTree(BinaryTreeNode* pRoot); //打印二叉树void DestroyTree(BinaryTreeNode* pRoot); //销毁二叉树
// 《剑指Offer——名企面试官精讲典型编程题》代码// 著作权所有者:何海涛#include "StdAfx.h"#include "BinaryTree.h"BinaryTreeNode* CreateBinaryTreeNode(int value) //创建二叉树节点{ BinaryTreeNode* pNode = new BinaryTreeNode(); pNode->m_nValue = value; pNode->m_pLeft = NULL; pNode->m_pRight = NULL; return pNode;}void ConnectTreeNodes(BinaryTreeNode* pParent, BinaryTreeNode* pLeft, BinaryTreeNode* pRight) //链接二叉树节点{ if(pParent != NULL) { pParent->m_pLeft = pLeft; pParent->m_pRight = pRight; }}void PrintTreeNode(BinaryTreeNode* pNode) //注意判断条件{ if(pNode != NULL) { printf("value of this node is: %d\n", pNode->m_nValue); if(pNode->m_pLeft != NULL) printf("value of its left child is: %d.\n", pNode->m_pLeft->m_nValue); else printf("left child is null.\n"); if(pNode->m_pRight != NULL) printf("value of its right child is: %d.\n", pNode->m_pRight->m_nValue); 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->m_pLeft != NULL) PrintTree(pRoot->m_pLeft); if(pRoot->m_pRight != NULL) PrintTree(pRoot->m_pRight); }}void DestroyTree(BinaryTreeNode* pRoot){ if(pRoot != NULL) { BinaryTreeNode* pLeft = pRoot->m_pLeft; BinaryTreeNode* pRight = pRoot->m_pRight; //一定要住一顺序 递归的顺序 首先总结重复步骤 ,归纳重复步骤,最后递归 delete pRoot; pRoot = NULL; DestroyTree(pLeft); DestroyTree(pRight); }}
0 0
- 关于数据结构的学习经验分享 (二叉树相关的内容)
- 关于数据结构的学习经验分享 (链表相关的内容)
- 关于数据结构的学习经验分享 (字符串相关的)
- 关于数据结构的学习经验分享 (1关于实现语言)
- 关于EasyUi学习的经验分享
- 数据结构 二叉搜索树的相关操作
- 【数据结构】搜索二叉树的相关操作
- 数据结构:二叉查找树的相关操作
- 数据结构中二叉树的相关操作
- 关于facebook分享的经验
- 【数据结构】二叉树的学习
- 数据结构与算法学习之二叉树及二叉树的相关操作
- 二叉树的相关学习
- 分享学习语言的经验
- 学习分享DBA的经验
- 师哥的学习经验分享
- 关于数据结构中二叉树的遍历
- 数据结构关于二叉树的操作
- JavaIO 系统
- python中inspect使用
- iOS html中嵌入图片适应手机屏幕大小
- JSP标准标签库(JSTL)网上文档
- 安卓实现微信分享——完整
- 关于数据结构的学习经验分享 (二叉树相关的内容)
- shell测试
- python filter()、map()、reduce()函数解析
- 程序员面试宝典(第5版)——互动出版网
- 位图BitMap图像的读取与存储
- 计算机网络之路由器与分组交换
- B返回A时,对A进行操作
- 2015程序员值得收藏的十大主流button模式
- iOS开发应用上传AppStore的步骤