Exemplo n.º 1
0
def ordering_insert(l, v):
    """
    Add *v* to list *l* such that *l* is kept ordered.

    :param l: An ordered list.
    :type l: dict
    :param v: The value to be inserted.
    :type v: same as elements of *l*
    """
    it = list.get_listiterator(l)
    ajouter = False
    while (list.hasNext(it) and not ajouter):
        if v < list.next(it):
            list.previous(it)
            list.add(it, v)
            ajouter = True
    if not ajouter:
        list.add(it, v)
Exemplo n.º 2
0
def print_with_iterator_reverse_bis(l):
    """
    Print elements of a list using an iterator in reverse order.

    :param l: The list to be printed
    :type l: dict
    """
    it = list.get_listiterator(l, r=True)
    while (list.hasPrevious(it)):
        print(list.previous(it), end=' ')
    print()
Exemplo n.º 3
0
def print_with_iterator_reverse_bis(l):
    """
    Print elements of a list using an iterator in reverse order.
    
    :param l: The list to be printed
    :type l: dict
    """
    l_iterator = list.get_listiterator(l, from_the_end=True)
    while list.hasPrevious(l_iterator):
        print(list.previous(l_iterator))
    return None
Exemplo n.º 4
0
def print_with_iterator_reverse(l):
    """
    Print elements of a list using an iterator in reverse order.

    :param l: The list to be printed
    :type l: dict
    """
    it = list.get_listiterator(l, from_the_end=True)

    while list.hasPrevious(it):
        print(list.previous(it)['value'], end=" ")

    print()
Exemplo n.º 5
0
def ordering_insert(l, v):
    """
    Add *v* to list *l* such that *l* is kept ordered.
    
    :param l: An ordered list.
    :type l: dict
    :param v: The value to be inserted.
    :type v: same as elements of *l*
    """
    if list.is_empty(l):
        cons(l, v)
        Found = True
    else:
        Found = False
        it = list.get_listiterator(l)
        while list.hasNext(it) and not Found:
            if v <= list.next(it):
                list.previous(it)
                list.add(it, v)
                Found = True
    if not Found:
        list.add(it, v)
    return None
Exemplo n.º 6
0
    list.print_list(l)

    # test 0 : impression renversee
    list.print_list(l, reverse=True)

    # test 1 : impression avec iterateurs
    print_with_iterator(l)
    print_with_iterator_reverse(l)

    # test 2 : insertion avant le 3eme element
    it = list.get_listiterator(l)
    print(list.next(it))
    print(list.next(it))
    list.add(it, 23)
    assert (list.previous(it)["value"] == 23)
    print_with_iterator(l)
    print_with_iterator_reverse(l)

    # test 3 : insertion apres le dernier element
    it = list.get_listiterator(l)
    while (list.hasNext(it)):
        list.next(it)
    list.add(it, 45)
    assert (list.previous(it)['value'] == 45)
    print_with_iterator(l)
    print_with_iterator_reverse(l)

    # test 4 : insertion avant le premier element
    it = list.get_listiterator(l)
    list.add(it, 0)
Exemplo n.º 7
0
    print('--- test 1 ---')
    print_with_iterator(l)
    print_with_iterator_reverse(l)

    # test 2 : verification des exceptions
    print('--- test 2 ---')
    try:
        it = list.get_listiterator(l)
        while True:
            list.next(it)
    except list.NoSuchElementException:
        print("Exception levee avec next")
    try:
        it = list.get_listiterator(l)
        while True:
            list.previous(it)
    except list.NoSuchElementException:
        print("Exception levee avec previous")

    # test 3 : insertion avant le 3eme element
    print('--- test 3 ---')
    it = list.get_listiterator(l)
    print(list.next(it))
    print(list.next(it))
    list.add(it, 23)
    assert (list.previous(it) == 23)
    print_with_iterator(l)
    print_with_iterator_reverse(l)

    # test 4 : insertion apres le dernier element
    print('--- test 4 ---')