Skip to content

Commit

Permalink
二分搜索树非递归前序遍历
Browse files Browse the repository at this point in the history
  • Loading branch information
liusishan committed Feb 20, 2019
1 parent f3746e5 commit 197bd28
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 06-Binary-Search-Tree/01-Binary-Search-Tree-Basics/src/BST.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringStack;

import java.util.Stack;

/**
* @Auther: lss
* @Date: 2019/1/30 21:40
Expand Down Expand Up @@ -90,6 +94,21 @@ private void preOrder(Node node) {
preOrder(node.right);
}

// 二分搜索树的非递归前序遍历
public void preOrderNR(){
Stack<Node> stack = new Stack<>();
stack.push(root);
while (!stack.isEmpty()){
Node cur = stack.pop();
System.out.println(cur.e);

if(cur.right!=null)
stack.push(cur.right);
if (cur.left!=null)
stack.push(cur.left);
}
}

// 二分搜索树的中序遍历
public void inOrder() {
inOrder(root);
Expand Down

0 comments on commit 197bd28

Please sign in to comment.