def print_with_iterator(l): """ Print elements of a list using an iterator. :param l: The list to be printed :type l: dict """ it = list.get_listiterator(l) while (list.hasNext(it)): print(list.next(it), end=' ') print()
def print_with_iterator(l): """ Print elements of a list using an iterator. :param l: The list to be printed :type l: dict """ l_iterator = list.get_listiterator(l) while list.hasNext(l_iterator): print(list.next(l_iterator)) return None
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 """ l_iterator = list.get_listiterator(l) while list.hasNext(l_iterator): list.next(l_iterator) while list.hasPrevious(l_iterator): print(list.previous(l_iterator)) return None
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
# 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) assert (list.previous(it)['value'] == 0) print_with_iterator(l) print_with_iterator_reverse(l) # test 5 : insertion avant le dernier element avec l'iterateur placé en fin it = list.get_listiterator(l, True)