public class TreeNode
{
public int val;
public TreeNode left;
public TreeNode right; public TreeNode(int x)
{
val = x;
}
}

打印代码

      private void WriteTreeNode(TreeNode node)
{
StringBuilder stringBuilder=new StringBuilder();
if (node == null)
{
Console.WriteLine("node is null");
return;
} stringBuilder.Append($"node is {node.val}");
if (node.left == null)
{
stringBuilder.Append(", node.left is null");
}
else
{
stringBuilder.Append($", node.left is {node.left.val}");
}
if (node.right == null)
{
stringBuilder.Append(", node.right is null");
}
else
{
stringBuilder.Append($", node.right is {node.right.val}");
}
Console.WriteLine(stringBuilder.ToString()); if (node.left != null)
{
WriteTreeNode(node.left);
}
if (node.right != null)
{
WriteTreeNode(node.right);
}
}

BinaryTree的更多相关文章

  1. [BinaryTree] 二叉树类的实现

    二叉树结点的抽象数据类型: template<class T> class BinaryTreeNode { friend class BinaryTree<T>; priva ...

  2. 数据结构与算法---线索化二叉树(Threaded BinaryTree)

    先看一个问题 将数列 {1, 3, 6, 8, 10, 14  } 构建成一颗二叉树 问题分析: 当我们对上面的二叉树进行中序遍历时,数列为 {8, 3, 10, 1, 6, 14 } 但是 6, 8 ...

  3. java数据结构——二叉树(BinaryTree)

    前面我们已经学习了一些线性结构的数据结构和算法,接下来我们开始学习非线性结构的内容. 二叉树 前面显示增.删.查.遍历方法,完整代码在最后面. /** * 为什么我们要学习树结构. * 1.有序数组插 ...

  4. 二叉树BinaryTree构建测试(无序)

    此测试仅用于二叉树基本的性质测试,不包含插入.删除测试(此类一般属于有序树基本操作). //二叉树树类 public class BinaryTree { public TreeNode root; ...

  5. Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference

    最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...

  6. binaryTree:普通二叉树

    #ifndef _Tree_H #define _Tree_H typedef int ElementType; typedef struct TreeNode { ElementType Eleme ...

  7. 数据结构之二叉树(BinaryTree)

    导读 二叉树是一种很常见的数据结构,但要注意的是,二叉树并不是树的特殊情况,二叉树与树是两种不一样的数据结构. 目录 一. 二叉树的定义 二.二叉树为何不是特殊的树 三.二叉树的五种基本形态 四.二叉 ...

  8. [Leetcode 104]求二叉树的深度Depth of BinaryTree

    [题目] Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...

  9. [BinaryTree] AVL树、红黑树、B/B+树和Trie树的比较

    转自:AVL树.红黑树.B/B+树和Trie树的比较 AVL树 最早的平衡二叉树之一.AVL是一种高度平衡的二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应 ...

随机推荐

  1. 升级 phpstud y中的 mysql 版本

    1.找到你 phpstudy 安装目录,找到 MySQL 文件夹 (我自己的实际目录  D:\pc\phpstudy\MySQL),关掉退出 phpstudy服务,删除 MySQL 文件夹里的文件,如 ...

  2. redis(四)--简单实现Redis缓存中的排序功能

    在实现缓存排序功能之前,必须先明白这一功能的合理性.不妨思考一下,既然可以在数据库中排序,为什么还要把排序功能放在缓存中实现呢?这里简单总结了两个原因:首先,排序会增加数据库的负载,难以支撑高并发的应 ...

  3. css 背景图片虚化效果

    转载地址:http://blog.csdn.net/ohehehou/article/details/51975539 需求:一个div设置了background: url,现在需要使图片背景模糊,d ...

  4. 11 vs2015 连接oracle 11g 数据库及相关问题

    1.下载Oracle Developer Tools for Visual Studio 2015 ,网址如下. http://www.oracle.com/technetwork/topics/do ...

  5. 使用LibreOffice修复受损的Office文档

    在工作中时常遇到Office文档损坏,用MS Office不能打开,有时候用LibreOffice(测试为4.2版本)可以打开,另存一下就好了. 此方法虽然不是100%管用,但在实际中大半都可以. 另 ...

  6. ZOJ 4062 - Plants vs. Zombies - [二分+贪心][2018 ACM-ICPC Asia Qingdao Regional Problem E]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4062 题意: 现在在一条 $x$ 轴上玩植物大战僵尸,有 $n$ ...

  7. Xcode工程编译错误之iOS开发之Xcode9报错 Compiling IB documents for earlier than iOS7 is no longer supported.

    概要: 在我们升级到Xcode9时,最低的编译版本为iOS8,但是在使用一些SDK的时候就会报出Compiling IB documents for earlier than iOS7 is no l ...

  8. linux iptables 防火墙简介

    iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的基于包过滤的防火墙工具,它的功能十分强大,使用非 ...

  9. 20190412 T-SQL语言一

    -- T-SQL ------------------------------------------------------ 例如1 什么是注释符 单行注释select *from kc /*sel ...

  10. python终端打印带颜色的print

    原理 实现过程:       终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关.       转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示 ...