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) while list.hasNext(it) and it['successor']['value'] < v: list.next(it) list.add(it, v)
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)
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
list.cons(l, i) 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)