public ArrayList<ArrayList<Integer>> zigzagLevelOrder(TreeNode root) {
        ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();

        if (root == null) {
            return result;
        }
        //if left to right order
        boolean leftToRight = true;
        //current level
        Stack<TreeNode> current = new Stack<TreeNode>();
        //next level
        Stack<TreeNode> next = new Stack<TreeNode>();
        //put root into current
        current.push(root);
        //start from the 0 level
        int level = 0;

        while (!current.isEmpty()) {
            //every new level add a list into the result
            if (result.size() == level) {
                ArrayList<Integer> temp = new ArrayList<Integer>();
                result.add(temp);
            }
            //add the node from the current level
            TreeNode currentNode = current.pop();
            result.get(level).add(currentNode.getVal());
            //add current level node's children to the next level
            //since use stack, FILO, level 0, lefttoright, level 1 righttoleft
            //p.s. the order
            if (leftToRight) {
                if (currentNode.getLeft() != null) {
                    next.push(currentNode.getLeft());
                }
                if (currentNode.getRight() != null) {
                    next.push(currentNode.getRight());
                }

            } else {
                if (currentNode.getRight() != null) {
                    next.push(currentNode.getRight());
                }
                if (currentNode.getLeft() != null) {
                    next.push(currentNode.getLeft());
                }

            }

            // current level is empty, swap current level and next level
            // reverse boolean leftToRight
            // level++;
            if (current.isEmpty()) {
                level++;
                leftToRight = !leftToRight;
                Stack<TreeNode> temp = current;
                current = next;
                next = temp;
            }
        }
        return result;
    }