二叉树的前中后序遍历的递归与非递归算法模版
2021-02-09 10:16
标签:节点 col ISE else val null value -o color 1.节点数据结构 2.递归 3.非递归 二叉树的前中后序遍历的递归与非递归算法模版 标签:节点 col ISE else val null value -o color 原文地址:https://www.cnblogs.com/zhihaospace/p/12751275.htmlpublic class Node {
public int value;
public Node left;
public Node right;
public Node(int data){
this.value = value;
}
}
public class Recur {
public void preOrderRecur(Node head){
if (head == null){
return;
}
System.out.println(head.value + " ");
preOrderRecur(head.left);
preOrderRecur(head.right);
}
public void inOrderRecur(Node head){
if (head == null){
return;
}
inOrderRecur(head.left);
System.out.println(head.value + " ");
inOrderRecur(head.right);
}
public void posOrderRecur(Node head){
if (head == null){
return;
}
posOrderRecur(head.left);
posOrderRecur(head.right);
System.out.println(head.value + " ");
}
}
import java.util.Stack;
public class UnRecur {
public void preOrderUnRecur(Node head) {
System.out.println("pre-order: ");
if (head != null) {
Stack
文章标题:二叉树的前中后序遍历的递归与非递归算法模版
文章链接:http://soscw.com/index.php/essay/53046.html