Skip to content

Listes Chaînées

Fonction d'insertion

python
def insertion(D: Doubly, value, index : int) -> Doubly:
    print("insertion doubly", D, "index", index)
    
    # Base case: insert at head or into empty list
    if index <= 0 or D is None:
        new = Doubly(value)
        if D is not None:
        # I D do exists, we attach D to the end of our new value
            new.next = D
            D.prev = new
        return new

    # Recursive case: insert into the rest of the list
    else:
        # We got one node further into the chain
        D.next = insertion(D.next, value, index - 1)
        # And then relink the chain if it was broken
        if D.next is not None:
            D.next.prev = D
        return D

Released under the GPL-3.0 License.