Package tree.binarytree;import java.util.stack;/** * binary tree in-sequence traversal: recursive and non-recursive implementation * * @author WL * */public class Bitreeinorder {//recursive implementation of the sequence traversal public static void Bitreeinorderbyrecursion (Bitreenode root) {if (root = null) {return;} Bitreeinorderbyrecursion (Root.leftnode); System.out.println (Root.data); bitreeinorderbyrecursion (Root.rightnode);} Non-recursive implementation of the middle sequence traversal public static void Bitreeinorder (Bitreenode root) {stack<bitreenode> Stack = new stack<bitreenode& gt; ();//stack, for storing two-fork tree nodes Bitreenode current = root;//The present node while (currently! = NULL | |!stack.empty ()) {while (current! = null) { Stack.push (current); current = Current.leftnode;} if (!stack.empty ()) {current = Stack.pop (); System.out.println (current.data); current = Current.rightnode;}}}
Java Data Structure Series-Tree (4): Recursive and non-recursive implementation of the middle sequence traversal of a two-fork tree