def order_nodes(tree, increase=True):
    """Rotate internal nodes of a tree so that child nodes are ordered by the
    number of descendants.

    Parameters
    ----------
    tree : skbio.TreeNode
        tree to order
    increase : bool, optional
        order nodes in increasing (True) or decreasing (False) order

    Returns
    -------
    skbio.TreeNode
        resulting ordered tree

    See Also
    --------
    is_ordered

    Examples
    --------
    >>> from skbio import TreeNode
    >>> tree = TreeNode.read(['(((a,b),(c,d,e)),((f,g),h));'])
    >>> print(tree)
    (((a,b),(c,d,e)),((f,g),h));
    <BLANKLINE>
    >>> tree_ordered = order_nodes(tree, False)
    >>> print(tree_ordered)
    ((h,(f,g)),((a,b),(c,d,e)));
    <BLANKLINE>
    """
    res = tree.copy()
    for node in res.postorder():
        if node.is_tip():
            node.n = 1
        else:
            node.n = sum(x.n for x in node.children)
    for node in res.postorder():
        if not node.is_tip():
            children = node.children
            node.children = []
            for child in sorted(children, key=lambda x: x.n, reverse=increase):
                node.append(child)
    for node in res.postorder():
        delattr(node, 'n')
    return res