def turn_cycle(cycle, front_node):
    """
    turn the list of the cycle to ensure frontnode is the first
    :param cycle: the cycle to be turned
    :param front_node: the node that needs to be at the front(and the back)
    :return: the turned cycle
    takes at most cyclelength -1 runs, so is bounded by O(V)
    """
    if front_node not in cycle:  # ensure it will not run forever because it lacks the required node
        raise Exception("incorrect use of turn_cycle function, front_node not in given cycle")
    while cycle[
        0] != front_node:  # as long as the node at the front is not the desired frontnode, make the second node the node at the front and check again
        cycle = cycle[1:]
        cycle += (cycle[0],)
    return cycle