BinaryTree
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的更多相关文章
- [BinaryTree] 二叉树类的实现
二叉树结点的抽象数据类型: template<class T> class BinaryTreeNode { friend class BinaryTree<T>; priva ...
- 数据结构与算法---线索化二叉树(Threaded BinaryTree)
先看一个问题 将数列 {1, 3, 6, 8, 10, 14 } 构建成一颗二叉树 问题分析: 当我们对上面的二叉树进行中序遍历时,数列为 {8, 3, 10, 1, 6, 14 } 但是 6, 8 ...
- java数据结构——二叉树(BinaryTree)
前面我们已经学习了一些线性结构的数据结构和算法,接下来我们开始学习非线性结构的内容. 二叉树 前面显示增.删.查.遍历方法,完整代码在最后面. /** * 为什么我们要学习树结构. * 1.有序数组插 ...
- 二叉树BinaryTree构建测试(无序)
此测试仅用于二叉树基本的性质测试,不包含插入.删除测试(此类一般属于有序树基本操作). //二叉树树类 public class BinaryTree { public TreeNode root; ...
- 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 ...
- binaryTree:普通二叉树
#ifndef _Tree_H #define _Tree_H typedef int ElementType; typedef struct TreeNode { ElementType Eleme ...
- 数据结构之二叉树(BinaryTree)
导读 二叉树是一种很常见的数据结构,但要注意的是,二叉树并不是树的特殊情况,二叉树与树是两种不一样的数据结构. 目录 一. 二叉树的定义 二.二叉树为何不是特殊的树 三.二叉树的五种基本形态 四.二叉 ...
- [Leetcode 104]求二叉树的深度Depth of BinaryTree
[题目] Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- [BinaryTree] AVL树、红黑树、B/B+树和Trie树的比较
转自:AVL树.红黑树.B/B+树和Trie树的比较 AVL树 最早的平衡二叉树之一.AVL是一种高度平衡的二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应 ...
随机推荐
- 网站favicon图标的显示问题
今天在微信开发者工具发现一个错误,说是找不到favicon.ico这个文件. 这个就是标签式浏览器显示在页面title前面的小图标,移动端也没什么用,所以一直没在意,今天有空就研究了一下,发现还是有点 ...
- 关于maven的CoreException: Could not get the value for parameter compilerId for plugin 。。的错误
在Eclipse中使用 Alt+F5 快捷键,在弹出的Update Maven Project对话框中选择报错的Maven工程,勾选下图中的 Force Update of Snapshots/Rel ...
- GC垃圾回收器
java与C++之间有一堵由内存动态分配和垃圾收集技术所围成的“高墙”.jvm解决的两个问题:给对象分配内存以及回收分配给对象的内存.GC:将内存中不再被使用的对象进行回收.GC的作用域是JVM运行时 ...
- vivado/FPGA 使用小纪
1.使用FPGA做为外部控制器的总线译码时,将总线时钟接在全局时钟脚上(MRCC),就算接在了局部时钟(SRCC)上,也要通过BUFG转为全局时钟走线,否则会因为local clk到各部分的时延较大引 ...
- ssh无输入密码登录问题
每天一个Linux命令:ps命令 ssh原理和运用(一):远程登录 http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html SSH是每 ...
- nexus2 配置
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- ES6 迭代器
Iterator Iterator 是 ES6 引入的一种新的遍历机制,迭代器有两个核心概念: 迭代器是一个统一的接口,它的作用是使各种数据结构可被便捷的访问,它是通过一个键为Symbol.itera ...
- windows 创建共享文件夹
1.右键要共享的文件夹----“共享”------“指定特定用户”,出现如下对话框: 2.选择“Everyone”,点击“共享”按钮,如下: 3.打开“运行“(win+r),输入上图 双反斜杠后面的内 ...
- WebMagic
一.WebMagic的四个组件 1.Downloader Downloader负责从互联网上下载页面,默认使用apache HttpClient作为下载工具 2.PageProcessor 负责解析页 ...
- Oracle不连续的值,如何实现查找上一条、下一条
1. 遇到的问题 已知一个题库,希望实现当前页切换上一题,下一题的需求. 查看得知,数据库中用于查询的字段(主键)是不连续的.如上图所示:stxh为主键number类型. 2. 实现方式lead ...