Java 二叉树遍历

BiTreenode.java public class BiTreeNode { private BiTreeNode leftChild; private BiTreeNode rightChild; public Object data; BiTreeNode(){ leftChild=null; rightChild=null; } 立即下载
本文转自百度文库

import java.util.Stack;
public class BiTree {
	private BiTree leftTree;// 左子树
	private BiTree rightTree;// 右子树
	private Object data;// 节点数据
	public final static int MAX = 40;
	BiTree[] elements = new BiTree[MAX];// 层次遍历时保存各个节点
	int front;// 层次遍历时队首
	int rear;// 层次遍历时队尾
	// 构造函数
	public BiTree() {
		// TODO Auto-generated constructor stub
	}
	public BiTree(Object data) {
		this.data = data;
	}
	public BiTree(Object data, BiTree lefTree, BiTree righTree) {
		this.data = data;
		this.leftTree = lefTree;
		this.rightTree = righTree;
	}
	// 递归前序遍历二叉树
	public void preOrder(BiTree tree) {
		if (tree != null) {
			visit(tree.data);
			preOrder(tree.leftTree);
			preOrder(tree.rightTree);
		}
	}
	// 非递归实现前序遍历
	public void iterativePreOrder(BiTree tree) {
		Stack<BiTree> stack = new Stack<BiTree>();
		if (tree != null) {
			stack.push(tree);
			while (!stack.isEmpty()) {
				tree = stack.pop();
				visit(tree.data);
				if (tree.rightTree != null)
					stack.push(tree.rightTree);
				if (tree.leftTree != null)
					stack.push(tree.leftTree);
			}
		}
	}
	// 递归中序遍历二叉树
	public void inOrder(BiTree tree) {
		if (tree != null) {
			inOrder(tree.leftTree);
			visit(tree.data);
			inOrder(tree.rightTree);
		}
	}
	// 非递归实现中序遍历
	public void iterativeInOrder(BiTree tree) {
		Stack<BiTree> stack = new Stack<BiTree>();
		while (tree != null) {
			while (tree != null) {
				if (tree.rightTree != null)
					stack.push(tree.rightTree);// 当前节点右子入栈
				stack.push(tree);// 当前节点入栈
				tree = tree.leftTree;
			}
			tree = stack.pop();
			while (!stack.empty() && tree.rightTree == null) {
				visit(tree.data);
				tree = stack.pop();
			}
			visit(tree.data);
			if (!stack.empty())
				tree = stack.pop();
			else
				tree = null;
		}
	}
	// 递归后序遍历二叉树
	public void postOrder(BiTree tree) {
		if (tree != null) {
			postOrder(tree.leftTree);
			postOrder(tree.rightTree);
			visit(tree.data);
		}
	}
	// 非递归实现后序遍历
	public void iterativePostOrder(BiTree tree) {
		BiTree tempTree = tree;
		Stack<BiTree> stack = new Stack<BiTree>();
		while (tree != null) {
			// 左子树入栈
			for (; tree.leftTree != null; tree = tree.leftTree)
				stack.push(tree);
			// 当前节点无右子或右子已经输出
			while (tree != null
					&& (tree.rightTree == null || tree.rightTree == tempTree)) {
				visit(tree.data);
				tempTree = tree;// 记录上一个已输出节点
				if (stack.empty())
					return;
				tree = stack.pop();
			}
			// 处理右子
			stack.push(tree);
			tree = tree.rightTree;
		}
	}
	// 层次遍历二叉树
	public void LayerOrder(BiTree tree) {
		elements[0] = tree;
		front = 0;
		rear = 1;
		while (front < rear) {
			try {
				if (elements[front].data != null) {
					System.out.print(elements[front].data + " ");
					if (elements[front].leftTree != null)
						elements[rear++] = elements[front].leftTree;
					if (elements[front].rightTree != null)
						elements[rear++] = elements[front].rightTree;
					front++;
				}
			} catch (Exception e) {
				break;
			}
		}
	}
	// 求二叉树的高度
	public static int height(BiTree tree) {
		if (tree == null)
			return 0;
		else {
			int leftTreeHeight = height(tree.leftTree);
			int rightTreeHeight = height(tree.rightTree);
			return leftTreeHeight > rightTreeHeight ? leftTreeHeight + 1
					: rightTreeHeight + 1;
		}
	}
	// 求data所对应结点的层数,如果对象不在树中,结果返回-1;否则结果返回该对象在树中所处的层次,规定根节点为第一层
	public int level(Object data) {
		int leftLevel, rightLevel;
		if (this == null)
			return -1;
		if (data == this.data)
			return 1;
		leftLevel = leftTree == null ? -1 : leftTree.level(data);
		rightLevel = rightTree == null ? -1 : rightTree.level(data);
		if (leftLevel < 0 && rightLevel < 0)
			return -1;
		return leftLevel > rightLevel ? leftLevel + 1 : rightLevel + 1;
	}
	// 求二叉树的结点总数
	public static int nodes(BiTree tree) {
		if (tree == null)
			return 0;
		else {
			int left = nodes(tree.leftTree);
			int right = nodes(tree.rightTree);
			return left + right + 1;
		}
	}
	// 求二叉树叶子节点的总数
	public static int leaf(BiTree tree) {
		if (tree == null)
			return 0;
		else {
			int left = leaf(tree.leftTree);
			int right = leaf(tree.rightTree);
			if (tree.leftTree == null && tree.rightTree == null)
				return left + right + 1;
			else
				return left + right;
		}
	}
	// 求二叉树父节点个数
	public static int fatherNodes(BiTree tree) {
		if (tree == null || (tree.leftTree == null && tree.rightTree == null))
			return 0;
		else {
			int left = fatherNodes(tree.leftTree);
			int right = fatherNodes(tree.rightTree);
			return left + right + 1;
		}
	}
	// 求只有一个孩子结点的父节点个数
	public static int oneChildFather(BiTree tree) {
		int left, right;
		if (tree == null || (tree.rightTree == null && tree.leftTree == null))
			return 0;
		else {
			left = oneChildFather(tree.leftTree);
			right = oneChildFather(tree.rightTree);
			if ((tree.leftTree != null && tree.rightTree == null)
					|| (tree.leftTree == null && tree.rightTree != null))
				return left + right + 1;
			else
				return left + right;/* 加1是因为要算上根节点 */
		}
	}
	// 求二叉树只拥有左孩子的父节点总数
	public static int leftChildFather(BiTree tree) {
		if (tree == null)
			return 0;
		else {
			int left = leftChildFather(tree.leftTree);
			int right = leftChildFather(tree.rightTree);
			if ((tree.leftTree != null && tree.rightTree == null))
				return left + right + 1;
			else
				return left + right;
		}
	}
	// 求二叉树只拥有右孩子的结点总数
	public static int rightChildFather(BiTree tree) {
		if (tree == null || tree.rightTree == null)
			return 0;
		else {
			int left = rightChildFather(tree.leftTree);
			int right = rightChildFather(tree.rightTree);
			if (tree.leftTree == null && tree.rightTree != null)
				return left + right + 1;
			else
				return left + right;
		}
	}
	// 计算有两个节点的父节点的个数
	public static int doubleChildFather(BiTree tree) {
		int left, right;
		if (tree == null)
			return 0;
		else {
			left = doubleChildFather(tree.leftTree);
			right = doubleChildFather(tree.rightTree);
			if (tree.leftTree != null && tree.rightTree != null)
				return (left + right + 1);/* 加1是因为要算上根节点 */
			else
				return (left + right);
		}
	}
	// 访问根节点
	public void visit(Object data) {
		System.out.print(data + " ");
	}
	// 将树中的每个节点的孩子对换位置
	public void exChange() {
		if (this == null)
			return;
		if (leftTree != null)
			leftTree.exChange();
		if (rightTree != null)
			rightTree.exChange();
		BiTree temp = leftTree;
		leftTree = rightTree;
		rightTree = temp;
	}
	//递归求所有结点的和
	public  static int getSumByRecursion(BiTree tree){
		if(tree==null){
			return 0;
		}
		else{
			int left=getSumByRecursion(tree.leftTree);
			int right=getSumByRecursion(tree.rightTree);
			return Integer.parseInt(tree.data.toString())+left+right;
		}
		
	}
	//非递归求二叉树中所有结点的和
	public static int getSumByNoRecursion(BiTree tree){
		Stack<BiTree> stack = new Stack<BiTree>();
		int sum=0;
		if(tree!=null){
			stack.push(tree);
			while(!stack.isEmpty()){
				tree=stack.pop();
				sum+=Integer.parseInt(tree.data.toString());
				if(tree.leftTree!=null)
				    stack.push(tree.leftTree);
				if(tree.rightTree!=null)
					stack.push(tree.rightTree);
			}
			
		}
		return sum;
		
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BiTree e = new BiTree(5);
		BiTree g = new BiTree(7);
		BiTree h = new BiTree(8);
		BiTree l = new BiTree(12);
		BiTree m = new BiTree(13);
		BiTree n = new BiTree(14);
		BiTree k = new BiTree(11, n, null);
		BiTree j = new BiTree(10, l, m);
		BiTree i = new BiTree(9, j, k);
		BiTree d = new BiTree(4, null, g);
		BiTree f = new BiTree(6, h, i);
		BiTree b = new BiTree(2, d, e);
		BiTree c = new BiTree(3, f, null);
		BiTree tree = new BiTree(1, b, c);
		System.out.println("递归前序遍历二叉树结果: ");
		tree.preOrder(tree);
		System.out.println();
		System.out.println("非递归前序遍历二叉树结果: ");
		tree.iterativePreOrder(tree);
		System.out.println();
		System.out.println("递归中序遍历二叉树的结果为:");
		tree.inOrder(tree);
		System.out.println();
		System.out.println("非递归中序遍历二叉树的结果为:");
		tree.iterativeInOrder(tree);
		System.out.println();
		System.out.println("递归后序遍历二叉树的结果为:");
		tree.postOrder(tree);
		System.out.println();
		System.out.println("非递归后序遍历二叉树的结果为:");
		tree.iterativePostOrder(tree);
		System.out.println();
		System.out.println("层次遍历二叉树结果: ");
		tree.LayerOrder(tree);
		System.out.println();
		System.out.println("递归求二叉树中所有结点的和为:"+getSumByRecursion(tree));
		System.out.println("非递归求二叉树中所有结点的和为:"+getSumByNoRecursion(tree));
		
		System.out.println("二叉树中,每个节点所在的层数为:");
		for (int p = 1; p <= 14; p++)
			System.out.println(p + "所在的层为:" + tree.level(p));
		System.out.println("二叉树的高度为:" + height(tree));
		System.out.println("二叉树中节点总数为:" + nodes(tree));
		System.out.println("二叉树中叶子节点总数为:" + leaf(tree));
		System.out.println("二叉树中父节点总数为:" + fatherNodes(tree));
		System.out.println("二叉树中只拥有一个孩子的父节点数:" + oneChildFather(tree));
		System.out.println("二叉树中只拥有左孩子的父节点总数:" + leftChildFather(tree));
		System.out.println("二叉树中只拥有右孩子的父节点总数:" + rightChildFather(tree));
		System.out.println("二叉树中同时拥有两个孩子的父节点个数为:" + doubleChildFather(tree));
		System.out.println("--------------------------------------");
		tree.exChange();
		System.out.println("交换每个节点的左右孩子节点后......");
		System.out.println("递归前序遍历二叉树结果: ");
		tree.preOrder(tree);
		System.out.println();
		System.out.println("非递归前序遍历二叉树结果: ");
		tree.iterativePreOrder(tree);
		System.out.println();
		System.out.println("递归中序遍历二叉树的结果为:");
		tree.inOrder(tree);
		System.out.println();
		System.out.println("非递归中序遍历二叉树的结果为:");
		tree.iterativeInOrder(tree);
		System.out.println();
		System.out.println("递归后序遍历二叉树的结果为:");
		tree.postOrder(tree);
		System.out.println();
		System.out.println("非递归后序遍历二叉树的结果为:");
		tree.iterativePostOrder(tree);
		System.out.println();
		System.out.println("层次遍历二叉树结果: ");
		tree.LayerOrder(tree);
		System.out.println();
        
		System.out.println("递归求二叉树中所有结点的和为:"+getSumByRecursion(tree));
		System.out.println("非递归求二叉树中所有结点的和为:"+getSumByNoRecursion(tree));
		
		System.out.println("二叉树中,每个节点所在的层数为:");
		for (int p = 1; p <= 14; p++)
			System.out.println(p + "所在的层为:" + tree.level(p));
		System.out.println("二叉树的高度为:" + height(tree));
		System.out.println("二叉树中节点总数为:" + nodes(tree));
		System.out.println("二叉树中叶子节点总数为:" + leaf(tree));
		System.out.println("二叉树中父节点总数为:" + fatherNodes(tree));
		System.out.println("二叉树中只拥有一个孩子的父节点数:" + oneChildFather(tree));
		System.out.println("二叉树中只拥有左孩子的父节点总数:" + leftChildFather(tree));
		System.out.println("二叉树中只拥有右孩子的父节点总数:" + rightChildFather(tree));
		System.out.println("二叉树中同时拥有两个孩子的父节点个数为:" + doubleChildFather(tree));
		
		
	}
}

【gateway nc adapter虚拟网卡 win11 联想】问题的解决 由于需要登录公司内网,于是启用奇安信VPN。但启动后报出网关未连接的问题,于是我检查了我的网络适配器,并尝试解决,以下给出几种我实践过程中的行动,并附带最后成功的解决方法。 阅读详情

相关推荐

在 PyCharm 中使用 Copilot

此外,要在 PyCharm 中使用 GitHub Copilot,您必须有效订阅 Copilot。在 PyCharm 中安装 GitHub Copilot 后,您现在可以将其用作项目的扩展。此外,它很容易安装在不同的 IDE 平台上,您还可以为特定编程语言启用 GitHub 插件。此外,按照以下步骤,您可以轻松地在 PyCharm 中安装 GitHub Copilot。此外,在 IDE 上使用 GitHub Copilot 时,您可以使用一些快捷方式。

一览无遗 1万+

java语言构造顺序树_数据结构(java语言描述)树(二叉树)的构建和遍历操作

二叉树:度为二的,分左右孩子的树。树结点的结构:package tree;public class BitreeNode {private Object data;//树结点的数据private BitreeNode lchild,rchild;//树结点的左右孩子结点public BitreeNode(){//无参构造函数this(null);}//构造一颗左孩子和右孩子都为空的二叉树结点pub...

weixin_29871897的博客 223

QNX Neutrino 进程间通信编程之Message-passing/Pulse

Interprocess Communication(IPC,进程间通信)在QNX Neutrino从一个嵌入式实时系统向一个全面的POSIX系统转变起着至关重要的作用。IPC是将在内核中提供各种服务的进程内聚在一起的粘合剂。在QNX中,消息传递是IPC的主要形式,也提供了其他的形式,除非有特殊的说明,否则这些形式也都是基于本地消息传递而实现的。本篇幅主要讲解Message-passing和Pulse。

zhuwade的博客 3534

二叉树的高度 java 利用递归和层次遍历两种方法

package edu.lnu.fang.BiTree;import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue;import edu.lnu.fang.BiTree.BinTreeTra.Node;/** * 求树的高度 * * @author

fangchao3652 7213

【文献阅读:信道估计】Deep Residual Learning Meets OFDM Channel Estimation

基于深度学习的信道估计技术

weixin_43178683的博客 1757

SAPGUI 与 ADT 的时代分野:在多云架构下,谁还能代表现代 SAP 开发

摘要(149字) SAP开发工具正经历代际更迭:SAPGUI基于专有协议(NI/DIAG)的厚客户端架构难以适配多云环境,而ADT(ABAP Development Tools)通过HTTP(S)协议和Eclipse生态成为ABAP Cloud/RAP开发的唯一入口。关键差异体现在:ADT支持CDS、行为定义等云原生对象建模,天然对齐BTP的零信任网络;集成ATC、Git等DevOps工具链;而SAPGUI无法创建RAP核心对象,在跨平台、自动化方面存在硬限制。官方文档明确将ADT作为Clean Core战

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 393

java实现二叉树及(层序,先序,中序,后序,节点查找)

你想要的二叉树

demoyi的博客 591

英伟达 Jetson AGX Thor 官方入门教程(二)CUDA、Docker、JetPack 设置

本文详细介绍了NVIDIA Jetson AGX Thor开发套件的安装与配置流程。主要内容包括:1) BSP安装的三种方法(Jetson ISO、SDK Manager和Linux刷写脚本)及其适用场景;2) Docker环境的完整配置步骤及测试方法;3) CUDA工具包的两种安装方式(容器化和原生安装)及其性能对比;4) JetPack SDK的安装选项。文章提供了详细的命令行操作指南和故障排除建议,帮助开发者快速搭建AI开发环境,充分发挥Jetson平台的硬件性能优势。

机器人控制与仿真应用 1740

二叉树各种遍历算法 Java 实现总结

PS: 作者是正在学习Java的小白,在这里会总结一些与Java相关知识(Java代码实现),如有不足,欢迎前来讨论指正,十分感谢 !!! 目录二叉树各种遍历算法 Java 实现总结0 二叉树简述0.0 概述0.1 分类0.2 数据结构1 二叉树的遍历1.1 前序遍历1.2 中序遍历1.3 后序遍历1.4 层序遍历1.5 小总结 二叉树各种遍历算法 Java 实现总结 0 二叉树简述 0.0 概述 二叉树是树的特殊一种,具有如下特点: 1、每个结点最多有两颗子树,结点的度最大为2。 2、左子树和右子树是有顺

qq_41866626的博客 8184

AgentScope 2.0 API完全指南:构建企业级AI智能体应用的技术实践

本文系统梳理AgentScope 2.0框架的完整API体系,涵盖智能体核心引擎、统一模型适配层、工具系统、消息协议、权限控制与工作空间管理等七大核心模块。通过深入的源码级分析与架构图示,详细解读Agent类的推理-行动循环、ChatModelBase的多模型抽象、Toolkit的工具管理机制、ContentBlock的多模态内容表达、PermissionEngine的安全决策流程,以及Local/Docker/E2B三种工作空间实现。文章还提供了智能客服系统的完整实战案例,展示从自定义工具开发到流式服务部

program哲学 484

1、开启 Microsoft Power Automate 自动化之旅

本文介绍了 Microsoft Power Automate 的基本概念和其在信息时代自动化需求中的重要作用。Power Automate 是 Power Platform 的一部分,能够通过无代码/低代码的方式自动化处理重复性任务,例如邮件处理、文件复制等,从而提升工作效率。文章还详细讲解了 Power Automate 的核心术语、登录方式、创建第一个流程的操作步骤,并通过示例帮助用户快速上手。无论是终端用户还是管理员,都可以通过本文了解如何利用 Power Automate 实现业务流程自动化。

corn8的博客 170

Java 遍历二叉树

二叉树的核心操作 把所有的节点,按一定的次序,全部访问(针对这个数据,进行各种操作如:打印,修改,判定,计算......)一遍,访问过程中“不重不漏”。 分为:先序遍历、中序遍历、后序遍历、层序遍历 你都已看不到我们的好,我还为谁牵挂 ,你爱我还是他,是否沉默就是你的回答,我们都别挣扎 去爱他 DT

LL_break的博客 1200

零倾覆力矩点(ZMP)

从形式上讲,ZMP 指的是空间中相对于一个平面(通常是地平面)抵消接触力矩的点的集合。这个集合实际上是一个轴,而不是一个点,但为了方便起见,让我们按照传统的推导方法来计算地面平面上的 ZMP。这一推导从任何多刚体系统的牛顿-欧拉运动方程开始:其中,为机器人的总质量,为重力矢量,为系统的重心,为加速度,为固定点的角动量变化率。在右侧,表示净接触扭矩,即施加到机器人上的所有接触扭矩之和,坐标取自质心 (COM)。

机器人控制与仿真应用 2372

Java二叉树的前中后序遍历

本文章主要讲解了Java数据结构中何为二叉树的前中后序遍历,并附带了对应的题目,希望大家可以学习到二叉树的一些知识。

xinhang10的博客 3364

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

二叉树遍历——Java代码实现

二叉树遍历——Java的代码实现二叉树二叉树的遍历代码实现首先创建一个结点其次是进行遍历操作的BinaryTree类递归实现二叉树遍历方法详述(以中序遍历为例)主函数输出结果 二叉树 二叉树是树的一种,每个结点最多可具有两个子树,即结点的度最大为2。 二叉树的遍历 先序遍历:先访问根节点,然后访问左节点,最后访问右节点。 【1->2->4->8->9->5->10->3->6->7】 中序遍历:先访问左节点,然后访问根节点,最后访问右节点。 【8-&g

qq_40727800的博客 1637

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

JAVA遍历二叉树

二叉树的概念    二叉树(Binary Tree)是个有限元素的集合,该集合或者为空、或者由一个称为根(root)的元素及两个不相交的、被分别称为左子树和右子树的二叉树组成。当集合为空时,称该二叉树为空二叉树。在二叉树中,一个元素也称作一个结点。 现在我们给出一组二叉树 二叉树遍历又分为先序遍历(根节点-左子树 -右子树 )、中序遍历(左子树 -根节点-

The Best Or Nothing~ 5335

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

java实现二叉树的前序遍历、中序遍历、后序遍历

java实现二叉树的前序遍历、中序遍历、后序遍历

qq_50665369的博客 1394

java代码实现二叉树的遍历

一、二叉树的定义: 二叉树是树形结构的一个重要类型。许多实际问题抽象出来的数据结构往往是二叉树的形式,即使是一般的树也能简单地转换为二叉树,而且二叉树的存储结构及其算法都较为简单,因此二叉树显得特别重要。     二叉树(BinaryTree)是n(n≥0)个结点的有限集,它或者是空集(n=0),或者由一个根结点及两棵互不相交的、分别称作这个根的左子树和右子树的二叉树组成。     这个定义

想飞的企鹅 4615

java 遍历二叉树_java实现二叉树遍历的三种方式

本文实例为大家分享了java实现二叉树遍历的具体代码,供大家参考,具体内容如下二叉树如下:遍历结果如下:以下是实现代码:package binTree;import java.util.Stack;/*** @author bin.zhang* @version 2017年8月29日 上午10:22:01*/public class BinTreeTraversal {public static ...

weixin_42301009的博客 513

java中的二叉树遍历

抛出几个问题java中什么是二叉树?在java中怎么体现?怎么进行增删改查?

sutingStart的博客 1689

java实现二叉树的遍历_java实现二叉树遍历的三种方式

本文实例为大家分享了java实现二叉树遍历的具体代码,供大家参考,具体内容如下二叉树如下:遍历结果如下:以下是实现代码:package binTree;import java.util.Stack;/*** @author bin.zhang* @version 2017年8月29日 上午10:22:01*/public class BinTreeTraversal {public static ...

weixin_30724041的博客 731

java 遍历二叉树_二叉树java遍历实现

importjava.util.ArrayList;importjava.util.List;importorg.junit.Test;public classMyTree {private Node root = null;publicMyTree() {init();}private List list = new ArrayList();private voidinit() {Node e=...

weixin_34613462的博客 184

java的二叉树遍历_java实现二叉树遍历的三种方式

本文实例为大家分享了java实现二叉树遍历的具体代码,供大家参考,具体内容如下二叉树如下:遍历结果如下:以下是实现代码:package binTree;import java.util.Stack;/*** @author bin.zhang* @version 2017年8月29日 上午10:22:01*/public class BinTreeTraversal {public static ...

weixin_29597551的博客 179

java 递归二叉树遍历二叉树_Java通过递归进行二叉树遍历

搜索热词下面是编程之家 jb51.cc 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。// 测试二叉树遍历,递归算法public class TestBinaryTree {public static void main(String[] args) {Node g = new Node("G",null,null);Node e = new Node("E",null...

weixin_42549723的博客 322

java前序遍历,中序遍历,后序遍历二叉树

最近总结了下,二叉树的遍历的非递归实现过程,以下是整个java实现过程 package com.test.dayumianshi; import java.util.*; public class BinaryTreeRank { //存储除根结点所有节点的集合 private static List<Node> list = new ArrayList<...

苍白大神的博客 2276

java实现简单的二叉树遍历,Java 实现二叉树,以及遍历实现。

一个简单的构造二叉树,和通过递归的方式来实现二叉树的便利方式,1.前序遍历2.中序遍历3.后续遍历1.[代码][Java]代码package BinaryTree;public class BinaryTree {// design node for treepublic void printNode(TreeNode node) {System.out.print(node.getData())...

weixin_33359523的博客 163
上一篇: 零碎知识。
下一篇: Comparable 和 Comparator接口
RockCode_li
博客等级 码龄12年 3粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值