public static TreeNode flattenTree(BinaryTree tree)
    {
        TreeNode curNode = tree.mRoot;
        Stack<TreeNode> stack = new Stack<TreeNode>();

        while(!stack.empty())
        {
            if(curNode.getRight() != null)
                stack.push(curNode.getRight());
            if(curNode.getLeft() != null)
            {
                curNode.setRight(curNode.getLeft());
                curNode.setLeft(null);
            }
            else
            {
                TreeNode tempNode = stack.pop();
                curNode.setRight(tempNode);
            }

            curNode = curNode.getRight();
        }

        return tree.mRoot;
    }