赞
踩
package dataStruct;
import java.util.Stack;
/**
* 将二叉树的左右子树交换 非递归实现
* @author YangYi
*/
public class SwapTree {
private static Stack stack = new Stack();
public static void main(String args[]) {
Node root = buildTree();
inOrderVisit(root);
swapTree(root);
System.out.println();
inOrderVisit(root);
}
public static void inOrderVisit(Node root) {
if (root == null)
return;
inOrderVisit(root.left);
System.out.print(root.data);
inOrderVisit(root.right);
}
public static void swapTree(Node root) {
if (root == null)
return;
Node temp = null;
stack.push(root);
while (!stack.isEmpty()) {
Node node = stack.peek();
if (node.left =
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。