예제 #1
0
 def add(self, item):
     if self.head == None:
         self.head = Node(item)
     else:
         temp = Node(item)
         temp.set_next(self.head)
         self.head.set_previous(temp)
         self.head = temp
예제 #2
0
 def insert_after(self, item, x):
     if self.head == None:
         print("List is empty")
     else:
         current = self.head
         found = False
         while current != Nonde and not found:
             if current.get_item() == x:
                 found = True
             else:
                 current = current.get_next()
         if found == False:
             print("item is not in the list")
         else:
             temp = Node(item)
             temp.set_next(current.get_next())
             temp.set_previous(current)
             if current.get_next() != None:
                 current.get_next().set_previous(temp)
             current.set_next(temp)