public ArrayList<ArrayList<Integer>> levelOrderBottom(TreeNode root) {
		ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
		
		if (root == null) return result;
		
		Queue<TreeNode> queue = new LinkedList<TreeNode>();
		ArrayList<ArrayList<Integer>> tempList = new ArrayList<ArrayList<Integer>>();
		
		queue.add(root);
		
		while (!queue.isEmpty()) {
			ArrayList<TreeNode> tempNode = new ArrayList<TreeNode>();
			ArrayList<Integer> tempValue = new ArrayList<Integer>();
			
			//  the inner while loop is necessary for parsing one level of the tree
			while (!queue.isEmpty()) {
				TreeNode node = queue.remove();
				tempNode.add(node);
				tempValue.add(node.val);
			}
			
			tempList.add(tempValue);
			
			for (int i = 0; i < tempNode.size(); i++) {
				TreeNode n = tempNode.get(i);
				if (n.left != null) queue.add(n.left);
				if (n.right != null) queue.add(n.right);
			}
		}
		
		for (int i = tempList.size() - 1; i >= 0; i--) {
			result.add(tempList.get(i));
		}
		
		return result;
	}