コード例 #1
0
    def insert(self, item, index):
        current = self.head
        previous = None
        counter = self.length() - 1
        while counter > index:
            previous = current
            current = current.getNext()
            counter -= 1

        temp = Node(item)
        if previous is None:
            self.head = temp

        previous.setNext(temp)
        temp.setNext(current)

        self.len += 1
コード例 #2
0
    def add(self, item):
        current = self.head
        previous = None
        stop = False
        while current is not None and not stop:
            if current.getData() > item:
                stop = True
            else:
                previous = current
                current = current.getNext()

        temp = Node(item)
        if previous is None:
            temp.setNext(self.head)
            self.head = temp
        else:
            temp.setNext(current)
            previous.setNext(temp)
        self.len += 1
コード例 #3
0
 def add(self, item):
     temp = Node(item)
     temp.setNext(self.head)
     self.head = temp
     self.len += 1