博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建二叉树和遍历二叉树
阅读量:3966 次
发布时间:2019-05-24

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

#include

#include<stdio.h>
#include<stdlib.h>
typedef struct tree
{
int nValue;
struct tree *pLeft;
struct tree *pRight;
}Tree;
void CreateTree(Tree **ptree)
{
int num;
scanf("%d",&num);
if(num == 0)return;
(ptree) = (Tree)malloc(sizeof(Tree));
(*ptree)->nValue = num;
(*ptree)->pLeft = NULL;
(*ptree)->pRight = NULL;
CreateTree(&((ptree)->pLeft));
CreateTree(&((ptree)->pRight));
}
void print(Tree
zhi){
if(zhi==NULL){
return ;
}
if(zhi!=NULL){
printf("%d ",zhi->nValue);
print(zhi->pLeft);
print(zhi->pRight);
}
}
using namespace std;
int main()
{
Tree ptree = (Tree)malloc(sizeof(Tree));
int a;
cin>>a;
ptree->nValue=a;
tree
first=ptree;
CreateTree(&ptree->pLeft);
CreateTree(&ptree->pRight);
print(first);
return 0;
}

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

你可能感兴趣的文章
linux 常用命令以及技巧
查看>>
记录1年免费亚马逊AWS云服务器申请方法过程及使用技巧
查看>>
golang文章
查看>>
linux的system () 函数详解
查看>>
在shell脚本的第一行中,必须写#!/bin/bash
查看>>
一句话##错误 'ASP 0116' 丢失脚本关闭分隔符
查看>>
文件上传漏洞之.htaccess
查看>>
常见网络安全设备默认口令
查看>>
VirtualBox虚拟机网络配置
查看>>
oracle vm virtualbox虚拟机下,CentOS7系统网络配置
查看>>
解决Linux CentOS中cp -f 复制强制覆盖的命令无效的方法
查看>>
wdcpv3升级到v3.2后,多PHP版本共存的安装方法
查看>>
PHP统计当前网站的访问人数,访问信息,被多少次访问。
查看>>
Windows10远程报错CredSSP加密oracle修正
查看>>
Windows server 2016 设置多用户登陆
查看>>
偶然发现的面包屑
查看>>
CentOS 7 下挂载NTFS文件系统磁盘并设置开机自动挂载
查看>>
非插件实现Typecho语法高亮
查看>>
windows 下 netsh 实现 端口映射(端口转发)
查看>>
两个好用的命令行工具 watch 和 rsync
查看>>