标准建立二叉树NEW
#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的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- 【IT笔试面试题整理】给定二叉树先序中序,建立二叉树的递归算法
[试题描述]: 给定二叉树先序中序,建立二叉树的递归算法 其先序序列的第一个元素为根节点,接下来即为其左子树先序遍历序列,紧跟着是右子树先序遍历序列,固根节点已可从先序序列中分离.在中序序列中找到 ...
- 数据结构实习 - problem K 用前序中序建立二叉树并以层序遍历和后序遍历输出
用前序中序建立二叉树并以层序遍历和后序遍历输出 writer:pprp 实现过程主要是通过递归,进行分解得到结果 代码如下: #include <iostream> #include &l ...
- Pre- and Post-order Traversals(先序+后序序列,建立二叉树)
PAT甲级1119,我先在CSDN上面发布的这篇文章:https://blog.csdn.net/weixin_44385565/article/details/89737224 Suppose th ...
- 数据结构之二叉树篇卷一 -- 建立二叉树(With Java)
一.定义二叉树节点类 package tree; public class Node<E> { public E data; public Node<E> lnode; pub ...
- [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 ...
- [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 ...
随机推荐
- mysql insert中文乱码无法插入ERROR 1366 (HY000): Incorrect string value
ERROR 1366 (HY000): Incorrect string value: '\xB1\xEA\xCC\xE2\xD5\xE2...' for column 'title' at row ...
- 何使用CSS写出一个下拉菜单。
导航菜单是每个网站所必备的功能,也是每个学习制作网站的朋友所必须接触的,如何用css样式制作一个简单漂亮的二级下拉菜单呢? 下面为大家分享一下我的经验 方法步骤: 第一步 : 首页我们打开Subli ...
- panel控件 换行
Panel1.Controls.Add(new LiteralControl("<BR/>"));
- Tomcat启动报ClassNotFoundException错误,解决
今天把一个Maven管理的web项目Update后,启动Tomcat(Eclipse中)系统报错.错误提示 java.lang.ClassNotFoundException: ,显示是spring的C ...
- (转)OpenGL中位图的操作(glReadPixels,glDrawPixels和glCopyPixels应用举例)
(一)BMP文件格式简单介绍 BMP文件是一种像素文件,它保存了一幅图象中所有的像素.这种文件格式可以保存单色位图.16色或256色索引模式像素图.24位真彩色图象,每种模式种单一像素的大小分别为1/ ...
- C语言常用的库文件(头文件、函数库)
C语言常用的库文件(头文件.函数库) C系统提供了丰富的系统文件,称为库文件.C的库文件分为两类,一类是扩展名为".h"的文件,称为头文件,在前面的包含命令中我们已多次使用过.在& ...
- 表格(table) 插件:支持当前行增行、删除。使用事件委托
最近做一个项目,需要对表格进行增行和删行. 研究了一下jquery操作dom的方法和事件委托原理,下面是我编写的例子,源码传上,欢迎高手指点. 功能: 支持在指定行下面增行: 支持删行指定行: 增行. ...
- Android.Hack.02_Animations
#01# TextView 和 ImageView TextView和Imageview切换卡顿,为了实现更好的切换,可以用动画来实现,系统自带的TextViewSwitcher 和ImageView ...
- CSS 3 属性学习大纲
1. Gradient 渐变 2. RGBA 颜色透明 3. Border-radius 圆角 4. text-shadow 文字阴影 5. box-shadow 图层阴影 6. Transform ...
- 列表checkbox全选
$(document).ready(function(){ $(":checkbox:eq(0)").change(function(){ if ($(this).is(" ...