def add(self, item): if not self.head: temp = Node(item) temp.setNext(self.head) self.head = temp else: current = self.head previous = None found = False while current != None: if current.getData() > item: found = True temp = Node(item) temp.setNext(current) if not previous: self.head = temp else: previous.setNext(temp) break else: previous = current current = current.getNext() if not found: self.addAtEnd(item) if not self.last: self.last = self.head
def add(self, item): temp = Node(item) temp.setNext(self.head) self.head = temp print(temp)