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是一种高度平衡的二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应 ...
随机推荐
- v-if和v-show
1.v-if 当值为 true时,显示元素 ,当值为false时,改元素消失------------------(销毁与重建dom) 2.v-show 当值为 true时,显示元素(display:b ...
- js中级小知识4
1.针对表单 form input select textarea type="radio/checkbox/passdord/button/submit/reset/ ...
- dubbo控制器xml文件报错
在配置dubbo服务的过程中,经常会遇到虽然程序能够跑起来,但是配置文件一堆红叉,虽然不影响功能,但是确实很让人恶心. 报错信息如下: Multiple annotations found at th ...
- JavaScript基础知识(Number的方法)
Number的方法 number : 数字 正数 负数 0 NaN 小数; NaN : not a number; 不是一个数字,但是属于数字类型的: 1.typeof :检测当前的数据类型的: 首先 ...
- sql中join与left-join图解区别
select a.* from YG_BRSYK a left join(SELECT DISTINCT SYXH, STUFF((SELECT '.'+MS FROM #lsb where SY ...
- [No0000195]NoSQL还是SQL?这一篇讲清楚
随着大数据时代的到来,越来越多的网站.应用系统需要支撑海量数据存储,高并发.高可用.高可扩展性等特性要求. 传统的关系型数据库在应付这些已经显得力不从心,并暴露了许多难以克服的问题. 由此,各种各样的 ...
- GDB调试原理——ptrace系统调用
本文由霸气的菠萝原创,转载请注明出处:http://www.cnblogs.com/xsln/p/ptrace.html 全部关于gdb的文章索引请点这里 引子: gdb基本上大家都在用,你有没有想过 ...
- TP框架中分页类的使用
public function test(){ $m=M('Message'); import('ORG.Util.Page');// 导入分页类 $count = $m->count();// ...
- 接口测试工具-Jmeter使用笔记(九:跨线程组传递变量)
使用场景: 请求API需要授权令牌,但是授权令牌只需要获取一次,即可调用服务器上其他业务接口. 所以我想要把授权操作放在单独的一个线程,业务流放在其他线程. 这就需要我把从授权线程获取的令牌传入业务流 ...
- java之jdbc使用
简单使用 Statement 通过 Statement 执行 ,其实是拼接 sql 语句的. 先拼接 sql 语句,然后在一起执行. package com.zze.test; import jav ...