面试篇:算法(二:二叉树)

一:创建节点

c 复制代码
class Node(
	public int idata; 	--节点
	public int Ddata;	--节点数据
	public Node LeftChild;	--左节点
	public Node RightChild;	--右节点
	public void prints(
		System.out.print(Data);
	)

二:遍历

1. 前序遍历。

c 复制代码
public void preOrder(Node node){
			if(node.idata = null)
			{return;}
			else
			{
				node.prints;
				beforFind(LeftChild);
				beforFind(RightChild);
			}

2. 中序遍历。

c 复制代码
	public void inOrder(Node node){
			if(node.idata = null)
			{return;}
			else
			{
				beforFind(LeftChild);
				node.prints;
				beforFind(RightChild);
			}
			
		}

3. 后序遍历。

c 复制代码
	public void postOrder(Node node){
			if(node.idata = null)
			{return;}
			else
			{
				beforFind(LeftChild);
				beforFind(RightChild);
				node.prints;
			}
			
		}

4. 层序遍历。

c 复制代码
	public void levelOrder(TreeNode node)
	{
		TreeNode cur=node;
		if (cur == null)
			{return;}
		else
		{
			Queue<Treenoede> queue=new LinkedList<>();
			queue.offer(cur);
			while(queue ! = null)
			{
				system.out.print(queue.poll().val);
				if(cur.left ! =null )
				{
					queue.offer(cur.left);
				}
				if(cur.right ! =null )
				{
					queue.offer(cur.right);
				}
			}
		}
	
	}
相关推荐
PAK向日葵2 小时前
【算法导论】PDD 0817笔试题题解
算法·面试
桦说编程4 小时前
Java 中如何创建不可变类型
java·后端·函数式编程
lifallen4 小时前
Java Stream sort算子实现:SortedOps
java·开发语言
IT毕设实战小研4 小时前
基于Spring Boot 4s店车辆管理系统 租车管理系统 停车位管理系统 智慧车辆管理系统
java·开发语言·spring boot·后端·spring·毕业设计·课程设计
地平线开发者4 小时前
ReID/OSNet 算法模型量化转换实践
算法·自动驾驶
地平线开发者5 小时前
开发者说|EmbodiedGen:为具身智能打造可交互3D世界生成引擎
算法·自动驾驶
没有bug.的程序员5 小时前
JVM 总览与运行原理:深入Java虚拟机的核心引擎
java·jvm·python·虚拟机
甄超锋5 小时前
Java ArrayList的介绍及用法
java·windows·spring boot·python·spring·spring cloud·tomcat
星星火柴9366 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
阿华的代码王国6 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端