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. GetLastError获取到错误代码的含义

    在写win32的时候我们会用到GetLastError()函数来获取程序错误信息,那我们如何从返回的数字得到错误信息. 这里推荐一个博客,总结了所以返回数字的错误信息: http://blog.csd ...

  2. weblogic反序列化漏洞CVE-2018-2628-批量检测脚本

    #coding=utf-8 import socket import time import re,os,sys,codecs type = 'utf-8' reload(sys) sys.setde ...

  3. 我也来----xia bi bi 一下----微信小程序

    工作刚到一阶段 就看了看微信小程序  自己做了个小dome 主要是为了让我女朋友能够学习做菜! 然而悲催的发现我根本没有App ID   不说快了  直接上图 个人感觉开发起来还是很简单的. 对着AP ...

  4. python----运行机制

    Python 是一门解释型的编程语言,因此它具有解释型语言的运行机制. 计算机程序,其实就是一组计算机指令集,能真正驱动机器运行的是机器指令,但让普通开发者直接编写机器指令是不现实的,因此就出现了计算 ...

  5. js方法的积累

    对字符串编码解码编码  encodeURIComponet(str); 解码  decodeURIComponet(str); 及时反应的方法,监听input值是否发生改变$('#username') ...

  6. 线程同步-Barrier类

    Barrier类:用于组织多个线程及时在某一个时刻碰面.并提供了一个回调函数,每次线程调用了SignalAndWait方法后该回调函数会被执行. 代码Demo: using System;using ...

  7. centos7磁盘在线扩容

    1.添加新磁盘 2.fdisk -l查看磁盘被识别的名称 3.如果输入fdisk -l命令没有找到新的磁盘,按下面步骤操作 1)进入到cd /sys/class/scsi_host/ 2)echo & ...

  8. PHP实现数组中每个字符出现次数最多的,并且如果两个字符出现相同,则在前面的先输出功能

    $arr = ['a', 'b', 'a', 'e', 'g', 'g', 'a']; $count_per_values = array_count_values($arr); $res = []; ...

  9. 高性能Nginx服务器-反向代理

    Nginx Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供 ...

  10. python进阶之 网络编程

    1.tcp和udp协议的区别 TCP协议 面向连接\可靠\慢\对传递的数据的长短没有要求 两台机器之间要想传递信息必须先建立连接 之后在有了连接的基础上,进行信息的传递 可靠 : 数据不会丢失 不会重 ...