// Use First Child / Next Sibling tree representation public class DemoNextSib { private static class NSNode { E data; NSNode nextSib; NSNode firstChild; public NSNode(E data,NSNode nextSib,NSNode firstChild) { this.data = data; this.nextSib = nextSib; this.firstChild = firstChild; } } private static void visit(NSNode node, int depth) { for (int i=0; i aaa=new NSNode("AAA",null,null); NSNode adc=new NSNode("ADC",null,null); NSNode ae =new NSNode("AE", null,null); NSNode adb=new NSNode("ADB",adc, null); NSNode ada=new NSNode("ADA",adb, null); NSNode ad =new NSNode("AD", ae, ada); NSNode ac =new NSNode("AC", ad, null); NSNode ab =new NSNode("AB", ac, null); NSNode aa =new NSNode("AA", ab, null); NSNode a =new NSNode("A", null,aa); System.out.printf("Preorder\n--------\n"); preorderTraverse(a, 0); System.out.printf("\n\n---------------\n\n\nPostorder\n---------\n"); postorderTraverse(a, 0); } } // Local Variables: // c-basic-offset: 2 // compile-command: "javac DemoNextSib.java && java DemoNextSib" // End: