Created
September 17, 2015 03:10
-
-
Save ejcer/e69bb3cdb961c7a96a38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void printStuffWrapper(Node root){ | |
if(node == null){ | |
System.out.println("wat"); | |
} | |
LinkedList<Character> pathString = new LinkedList<Character>(); | |
printStuff(node, pathString); | |
} | |
public static void printStuff(Node root, LinkedList<Character> pathString){ | |
pathString.add(root.data); | |
if(root.isLeaf()){ | |
printPath(pathString); | |
return; | |
} | |
if(root.left != null){ | |
printStuff(root.left, pathString); | |
pathString.removeLast(); | |
} | |
if(root.right != null){ | |
printStuff(root.right, pathString); | |
pathString.removeLast(); | |
} | |
} | |
public static void printPath(LinkedList<Character> pathString){ | |
StringBuilder sb = new StringBuilder(); | |
LinkedListNode<Character> lln = pathString.getFirst(); | |
for(int i = 0; i < pathString.size(); i++){ | |
sb.append(lln.data); | |
lln = lln.next; | |
} | |
System.out.println(sb.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment