#include<iostream>
#include<sstream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<time.h>
#define LEN 1000
#define INF 99999
using namespace std; struct node{
string data;
node *left;
node *right;
};
typedef node *BiTree;//定义新类型 看成结点!! void createtree(BiTree *t)//传递给我结点的指针t
{
string s; cin>>s; if(s=="#")
{
(*t)=NULL; // 既然t是结点的指针 // (*t)就是对应结点 下面同样如此
return;
} (*t)=new node; (*t)->data=s;
createtree(&(*t)->left);
createtree(&(*t)->right);
} void lastvisit(BiTree t)//后序遍历不用解释
{
if(t==NULL) return; lastvisit(t->right);
lastvisit(t->left);
cout<<t->data<<endl;
} int main()
{
BiTree T;
createtree(&T);//主意这里容易出错 &T//由于函数的原理,只有传递指针类型才能对树进行创立
lastvisit(T); return 0;
}

  

标准建立二叉树NEW的更多相关文章

  1. [LeetCode] Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  2. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal (用先序和中序树遍历来建立二叉树)

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  3. LeetCode 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树 C++

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. 【IT笔试面试题整理】给定二叉树先序中序,建立二叉树的递归算法

    [试题描述]:  给定二叉树先序中序,建立二叉树的递归算法 其先序序列的第一个元素为根节点,接下来即为其左子树先序遍历序列,紧跟着是右子树先序遍历序列,固根节点已可从先序序列中分离.在中序序列中找到 ...

  5. 数据结构实习 - problem K 用前序中序建立二叉树并以层序遍历和后序遍历输出

    用前序中序建立二叉树并以层序遍历和后序遍历输出 writer:pprp 实现过程主要是通过递归,进行分解得到结果 代码如下: #include <iostream> #include &l ...

  6. Pre- and Post-order Traversals(先序+后序序列,建立二叉树)

    PAT甲级1119,我先在CSDN上面发布的这篇文章:https://blog.csdn.net/weixin_44385565/article/details/89737224 Suppose th ...

  7. 数据结构之二叉树篇卷一 -- 建立二叉树(With Java)

    一.定义二叉树节点类 package tree; public class Node<E> { public E data; public Node<E> lnode; pub ...

  8. [LeetCode] 105. Construct Binary Tree from Preorder and Inorder Traversal 由先序和中序遍历建立二叉树

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  9. [LeetCode] 106. Construct Binary Tree from Inorder and Postorder Traversal 由中序和后序遍历建立二叉树

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

随机推荐

  1. Leetcode:best_time_to_buy_and_sell_stock_II题解

    一.题目 如果你有一个数组,它的第i个元素是一个股票在一天的价格. 设计一个算法,找出最大的利润. 二.分析 假设当前值高于买入值,那么就卖出,同一时候买入今天的股票,并获利.假设当前值低于买入值,那 ...

  2. Time Out 访问数据库超时处理 .NET

    using System.Reflection; using System.Data.SqlClient; TransactionSelectTableAdapter adapter = new Tr ...

  3. rem和em和px vh vw和% 移动端长度单位

    1.rem和em.px 首先来说说em和px的关系 em是指字体高度 浏览器默认1em=16px,所以0.75em=12px;我们经常会在页面上看到根元素写的font-size:65%; 这样em就成 ...

  4. Zepto.js touch模块深入分析 解决手机点击事件

    源码: // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT li ...

  5. sql生成20位数随机数

    declare @rnd nvarchar(50)set @rnd =''while LEN(@rnd)<20 begin set @rnd =@rnd + REPLACE ( CONVERT( ...

  6. IIS ,未能加载文件或程序集“System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。系统找不到指定的文件。

    1.解决办法:安装MSChart.exe程序 图表控件,下载附件,以管理员身份运行安装.

  7. 华为S5700基础配置----备份和恢复配置文件

    一:备份配置文件 设备作为FTP服务器,用户PC作为FTP客户端 # 配置设备的FTP功能及FTP用户信息. <HUAWEI> system-view [HUAWEI] ftp serve ...

  8. C++ 动态分配类对象

    1.概念 在C++中,类的对象建立分为两种,一种是静态建立,如A a:另一种是动态建立,如A* ptr=new A:这两种方式是有区别的. 静态建立一个类对象,是由编译器为对象在栈空间中分配内存,是通 ...

  9. CreateMutex() 、ReleaseMutex()

    功能: CreateMutex() 用于有独占要求的程序 (在其进程运行期间不允许其他使用此端口设备的程序运行,或不允许同名程序运行). 比如运行金山词霸时,一次只能运行一个实例,当运行第二个实例时, ...

  10. a 标签的四个伪类

    link        有链接属性时visited    链接地址已被访问过active     被用户激活(在鼠标点击与释放之间发生的事件)hover      其鼠标悬停 <!DOCTYPE ...