class TreeNode{ public int data; public TreeNode leftChild; public TreeNode rightChild; public static void inOrderTraversal(TreeNode node){ if(node == null){ return; }else{ inOrderTraversal(node.leftChild); System.out.println(node.data); inOrderTRaversal(node.rightChild); } }}
C#版本
/*public class BTNode //二叉樹節點類型{ public BTNode lchild; public BTNode rchild; public char data;}*//*public string btstr //全局變數*/public string InOrder(BTNode t){ btstr=""; InOrder1(r); returen btstr;}public string InOrder1(BTNode t){ if(t!=null) { InOrder(t.lchild); bster+=t.data.ToString()+" "; InOrder(t.rchild); }}
pascal版本
核心代碼:
procedure mid(bt:tree);begin if bt<>nil then begin mid (bt^.left); write(bt^.data); mid (bt^.right); end;end;