is my logic regarding sorted linked list implementation wrong?

you have some problem with the logic in append:

here you go:

def append(self, entry):
        n=Node(entry)
        if self.head is None:
            self.head = n
            return
        if self.head.content > entry:
            self.head, n.adjacent = n, self.head
            return
        
        tmp=self.head
        while tmp.adjacent and tmp.adjacent.content < entry:
            tmp=tmp.adjacent
        n.adjacent = tmp.adjacent
        tmp.adjacent = n

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top