Exemplo n.º 1
0
 def add(self, item):
     current = self.head
     pre = None
     temp = Node(item)
     while current != None:
         if current.getData() > item:
             break
         else:
             pre = current
             current = current.getNext()
     if pre == None:
         temp.setNext(self.head)
         self.head = temp
     else:
         temp.setNext(current)
         pre.setNext(temp)
Exemplo n.º 2
0
 def insert(self, pos, item):
     index = 0
     current = self.head
     pre = None
     temp = Node(item)
     if pos == index:
         self.add(item)
     else:
         while current != None:
             index += 1
             pre = current
             current = current.getNext()
             if index == pos:
                 temp.setNext(current)
                 pre.setNext(temp)
                 return
         return "Could not insert into the LinkList"
Exemplo n.º 3
0
 def add(self, item):
     temp = Node(item)
     temp.setNext(self.head)  #设置指向表头的下一个节点
     self.head = temp  #设置表头