## 2013年4月8日 星期一

### [ 文章收集 ] Inorder Tree Traversal without Recursion

1. package ref;
2.
3. public class Nodeextends Comparablesuper E>> {
4.     public Node left = null;
5.     public Node right = null;
6.     public E data;
7.     public Node(E data){this.data = data;}
8. }

1. public static Node GenTree1()
2. {
3.     Node root = new Node(1);
4.     root.left = new Node(2);
5.     root.right = new Node(3);
6.     root.left.left = new Node(4);
7.     root.left.right = new Node(5);
8.     return root;
9. }

1. public static void InorderRecur(Node node)
2. {
3.     if(node!=null)
4.     {
5.         InorderRecur(node.left); // Left
6.         System.out.printf("%s ", node.data); // Visit
7.         InorderRecur(node.right); // Right
8.     }
9. }

Inorder Tree Traversal without Recursion:

1) Create an empty stack S.
2) Initialize current node as root
3) Push the current node to S and set current = current->left until current is NULL
4) If current is NULL and stack is not empty then
>>a) Pop the top item from stack.
>>b) Print the popped item, set current = current->right
>>c) Go to step 3.
5) If current is NULL and stack is empty then we are done.

1. public static void Inorder(Node node)
2. {
3.     Stack> stack = new Stack>();
4.     Node curNode = node;
5.     while(curNode!=null || !stack.isEmpty())
6.     {
7.         while(curNode!=null)
8.         {
9.             stack.push(curNode);
10.             curNode = curNode.left;
11.         }
12.         curNode = stack.pop();
13.         System.out.printf("%s ", curNode.data);
14.         curNode = curNode.right;
15.     }
16. }

1. public static void main(String args[])
2. {
3.     Node root = GenTree1();
4.     Inorder(root);
5. }

4 2 5 1 3

Supplement:
[ 資料結構 小學堂 ] 樹狀結構導論 : 二元樹的走訪

### [NodeJS 文章收集] NodeJS accessing file with relative path

Source From  Here Question It seemed like a straight forward problem. But I am not able to crack this. Within  helper1.js  I would like to a...