
	// a reasonable attempt at a nice level-ordered print
	public String toString()
    {
		String result = "";
		int level = 0;
		String s;

		while ((s = levelString(root,level)) != null) {
	  		result += s + "\n";
			level++;
		}

		return result;
    }

    private String levelString(TreeNode rt, int level)
    {
		if (rt == null)
		    return null;

		if (level == 0)
		    return rt.getValue() + " ";

		String left = levelString(rt.getLeft(),level-1);
		String right = levelString(rt.getRight(),level-1);

		if (left == null && right == null)
			return null;

		String result = "";
		if (left != null)
			result += left;
		if (right != null)
			result += " " + right;
		return result;
    }
