二叉树的创建和遍历、删除
来源:互联网 发布:磐石投票软件 编辑:程序博客网 时间:2024/06/14 13:47
#include <stdio.h>#include <malloc.h>typedef struct BinaryTreeNode{struct BinaryTreeNode *pLeft;struct BinaryTreeNode *pRight;int mValue;}BINARYTREENODE;void CreateBinaryTree(BinaryTreeNode **pRoot){int value = 0;printf("Please Input a None Zero Value : ");scanf("%d",&value);printf("Value = %d\n",value);if(value == 0){*pRoot = NULL;return;}else{*pRoot = (BINARYTREENODE *)malloc(sizeof(BINARYTREENODE));printf("*pRoot = %x\n",*pRoot);printf("*pRoot = %x\n",pRoot);(*pRoot)->mValue = value;CreateBinaryTree(&((*pRoot)->pLeft));CreateBinaryTree(&((*pRoot)->pRight));}}void DeleteBinaryTree(BINARYTREENODE ** pRoot){if ((*pRoot)->pLeft == NULL && (*pRoot)->pRight == NULL){printf("Delete Node is %d\n",(*pRoot)->mValue);*pRoot = NULL;free(*pRoot);return;}else{DeleteBinaryTree(&((*pRoot)->pLeft));DeleteBinaryTree(&((*pRoot)->pRight));}}void ShowBinaryTree(BINARYTREENODE * pRoot){if (NULL!=pRoot){printf("%d ",pRoot->mValue);}}void PerOrder(BINARYTREENODE * pRoot){if (NULL!=pRoot){ShowBinaryTree(pRoot);PerOrder(pRoot->pLeft);PerOrder(pRoot->pRight);}}void InOrder(BINARYTREENODE * pRoot){if (NULL!=pRoot){InOrder(pRoot->pLeft);ShowBinaryTree(pRoot);InOrder(pRoot->pRight);}}void PostOrder(BINARYTREENODE * pRoot){if (NULL!=pRoot){PostOrder(pRoot->pLeft);PostOrder(pRoot->pRight);ShowBinaryTree(pRoot);}}int main(){BINARYTREENODE * pRoot = NULL;CreateBinaryTree(&pRoot);printf("%x\n",pRoot);printf("Find All Pre Order of Binary Tree : ");PerOrder(pRoot);printf("\n");printf("Find All In Order of Binary Tree : ");InOrder(pRoot);printf("\n");printf("Find All Post Order of Binary Tree : ");PostOrder(pRoot);printf("\n");printf("Before Delete %x\n",pRoot);while (pRoot!=NULL){DeleteBinaryTree(&pRoot);}printf("After Delete %x\n",pRoot);}
阅读全文
0 0
- 二叉树的创建和遍历、删除
- 二叉搜索树的创建和遍历
- 二叉树的创建,遍历和释放
- 简单的二叉树创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 数据结构---二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和前序中序后序遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉树的创建和遍历
- 二叉查找树的创建和遍历
- 二叉树的递归创建和遍历
- python爬取自己博客访问量
- OKHTTP3的依赖包与 权限
- Win10:怎么将在此处打开命令改为CMD
- 【MySql】mysql-5.7.19-winx64 的基本安装流程
- 安装Apache hadoop
- 二叉树的创建和遍历、删除
- 我国高等数学教材不能误导学生
- 记事本
- 用Eclipse Java图形用户界面加入图片,只有最大/小化才能显示图片。
- 虚拟机ubuntu net模式,主机能访问,局域网其他机器不能访问虚拟机。虚拟机要用桥接模式。
- 小白报道
- LeetCode----- 2.Add Two Numbers
- node.js
- 【makefile】一起写makefile(七) --make的运行