// Project: Recursion // Module: FamilyTree // Source code file: Main.java // Hard code this family tree: // // +---------John 78---------------+ // | | | // Arthur 56 Marjorie 54 Randolf 49 // / \ / \ | // / \ / \ | //Jason 35 Katie 30 Barry 32 Jennifer 28 Chloe 25 // | // Mason 10 // // Then print out in depth first order using a // recursive algorithm. public class Main { public static void main(String[] args) { // Create family tree. Person root = new Person("John", 78); root.addChild(new Person("Arthur", 56)); root.addChild(new Person("Marjorie", 54)); root.addChild(new Person("Randolf", 49)); root.getChild(0).addChild(new Person("Jason", 35)); root.getChild(0).addChild(new Person("Katie", 30)); root.getChild(1).addChild(new Person("Barry", 32)); root.getChild(1).addChild(new Person("Jennifer", 28)); root.getChild(2).addChild(new Person("Chloe", 25)); root.getChild(0).getChild(0). addChild(new Person("Mason", 10)); // Print the names in the family tree in // depth first order using a recursive // algorithm depthFirst(root); } public static void depthFirst(Person x) { int i, n; System.out.println(x); n = x.getNumberOfChildren(); for(i = 0; i <= n - 1; i++) depthFirst(x.getChild(i)); } }