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是一种高度平衡的二叉树,所以通常的结果是,维护这种高度平衡所付出的代价比从中获得的效率收益还大,故而实际的应 ...
随机推荐
- git 设置tracking information
There is no tracking information for the current branch.Please specify which branch you want to merg ...
- F#周报2019年第5期
新闻 Ionide的Open Collective 发布SAFE至Google Cloud Kubernetes引擎 .NET Core 3预览2 ASP.NET Core在.NET Core 3预览 ...
- [07-01]http网页提示含义
出现较多的一些网页代码提示的意思: 100 - 继续. 101 - 切换协议. 110 重新启动标记答复. 120 服务已就绪,在 nnn 分钟后开始. 125 数据连接已打开,正在开始传输. 150 ...
- Git服务器配置和基本使用
#git服务器搭建 1. 在系统中增加git用户 useradd -s /usr/bin/git-shell git 2. 在git用户的home目录下新建.ssh目录,做好相关配置 1)生成公私匙: ...
- IO调度算法的选择
一) I/O调度程序的总结 1) 当向设备写入数据块或是从设备读出数据块时,请求都被安置在一个队列中等待完成. 2) 每个块设备都有它自己的队列. 3) I/O调度程序负责维护这些队列的顺序,以更有效 ...
- 20175211 2018-2019-2 《Java程序设计》第二周学习总结
目录 教材学习内容总结 第二章 第三章 教材学习中的问题和解决过程 代码调试中的问题和解决过程 代码托管 上周考试错题总结 其他(感悟.思考等,可选) 学习进度条 参考资料 教材学习内容总结 第二章 ...
- HttpWebRequest请求http1.1的chunked的解析问题记录
问题:我的请求获取不到URL对应的内容(换个浏览器可以). 第一步对比wirshark截包看HTTP请求头,发现我这缺失一部分请求头. 对着官方文档添加即可.https://msdn.microsof ...
- C++ Windows API 读写INI文件
BOOL WritePrivateProfileString( LPCTSTR lpAppName, // INI文件中的一个字段名[节名]可以有很多个节名 LPCTSTR lpKeyName, // ...
- linux----------centos6.4安装完了以后敲ifconfig,没有局域网ip。解决如下
1.vim /etc/sysconfig/network-scripts/ifcfg-eth0 进入linux然后进入这个文件里面如下: DEVICE=eth0 HWADDR=00:0C:29:92: ...
- EasyUI相关知识点整理
EasyUI相关知识整理 EasyUI是一种基于jQuery.Angular..Vue和React的用户界面插件集合.easyui为创建现代化,互动,JavaScript应用程序,提供必要的功能.也就 ...