Exemplo n.º 1
0
    def add(self, item):
        current = self.head
        previous = None

        while current:
            if current.value > item:
                break
            previous, current = current, current.next

        temp = Node(item)
        if previous is None:
            temp.next, self.head = self.head, temp
        else:
            temp.next, previous.next = current, temp
Exemplo n.º 2
0
    def add(self, item):
        current = self.head
        previous = None

        while current is not None:
            if current.value > item:
                break
            previous, current = current, current.next

        temp = Node(item)
        if previous is None:
            temp.next, self.head = self.head, temp
        else:
            temp.next, previous.next = current, temp
Exemplo n.º 3
0
    def add(self, item):
        current = self.head
        previous = None

        while current is not None:
            if current.value > item:
                break
            previous = current
            current = current.next

        temp = Node(item)
        if previous == None:
            temp.next = self.head
            self.head = temp
        else:
            temp.next = current
            previous.next = temp


# ul = UnorderedList()
# ol = OrderedList()
# # ol.add(1)
# for i in range(1000):
# ul.add(i)
# ol.append(i)

# print("hji")
# # print(ol.print())
# import time
# start = time.time()

# # found = ul.search(250)

# end = time.time()

# print(found, end-start)

# ul
# True 0.031056880950927734
Exemplo n.º 4
0
    def add(self, item):
        current = self.head
        previous = None
        stop = False
        while current is not None and not stop:
            if current.get_data() > item:
                stop = True
            else:
                previous = current
                current = current.get_next()

        temp = Node(item)
        if previous is None:
            temp.set_next(self.head)
            self.head = temp
        else:
            temp.set_next(current)
            previous.set_next(temp)
Exemplo n.º 5
0
    def add(self, item):
        current = self.head
        prev = None
        stop = False

        while current != None and not stop:
            if current.getData() > item:
                stop = True
            else:
                prev = current
                current = current.getNext()

        temp = Node(item)
        if prev == None:  #插入在表头的情况
            temp.setNext(self.head)
            self.head = temp
        else:  #插入在表中
            temp.setNext(current)
            prev.setNext(temp)