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

一:创建节点

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);
				}
			}
		}
	
	}
相关推荐
非优秀程序员7 小时前
第05章 播放器大战,暴风、快播与那一夜|《互联网产品恩仇录》
算法
非优秀程序员7 小时前
第04章 邮箱大战,163 与 QQ 的暗战|《互联网产品恩仇录》
java·vue.js·架构
知已难寻7 小时前
Docker 入门:容器技术与 Docker 基础
java·运维·服务器·docker·云原生·容器
文丑颜不良啊9 小时前
LeetCode2481~2500题目解析
java·leetcode
Flynn Liang10 小时前
同一需求三套写法:用 Spring AI、LangChain4j、AgentScope Java 各实现一个带工具调用的 RAG 助手(实战对比)
java·人工智能·大模型·架构设计·spring ai·langchain4j·agentscope
聪明的笨猪猪11 小时前
实际工程问题:AI 生成 Spring Cache(@Cacheable / @CachePut / @CacheEvict)缓存注解踩坑
java·经验分享·面试·ai编程
愿有所息11 小时前
记一次 ARM64 + JDK8 上 fastjson2 的诡异数据错乱
java
秋饼12 小时前
MCP 2026-07-28 无状态协议大改版:Spring AI 2.1 多轮往返请求与网关路由落地
java·ai·技术分享·后端开发
SL_staff13 小时前
JVS-BI 实战:业务人员如何用零代码 ELT + 可视化配置构建实时经营分析闭环
java·spring·全栈