def traverse(node, order="pre-order", include_terminal=True, acc=None):
    """
    Parameters
    ----------
    node: NonTerminal or Terminal
    order: str, default "pre-order"
    include_terminal: bool, default True
    acc: list[T] or None, default None
        T -> NonTerminal or Terminal

    Returns
    -------
    list[T]
        T -> NonTerminal or Terminal
    """
    if acc is None:
        acc = []

    if node.is_terminal():
        if include_terminal:
            acc.append(node)
        return acc

    if order == "pre-order":
        # Process the current node
        acc.append(node)
        # Process the child nodes
        for c in node.children:
            acc = traverse(c, order=order, include_terminal=include_terminal, acc=acc)
    elif order == "post-order":
        # Process the child nodes
        for c in node.children:
            acc = traverse(c, order=order, include_terminal=include_terminal, acc=acc)
        # Process the current node
        acc.append(node)
    else:
        raise ValueError("Invalid order=%s" % order)

    return acc