コード例 #1
0
ファイル: my_solutions(2).py プロジェクト: tkchris93/ACME
 def add_node(self, data):
     """Create a new Node containing the data and add it 
     to the end of the list
     """
     new_node = DoublyLinkedListNode(data)
     if self.head is None:
         self.head = new_node
         self.tail = new_node
     else:
         self.tail.next = new_node
         new_node.prev = self.tail
         self.tail = new_node
コード例 #2
0
ファイル: my_solutions(2).py プロジェクト: tkchris93/ACME
 def insert_node(self, new_data, old_data):
     #check to see if it's empty
     if self.head is None:
         return
     
     #if inserting at the head
     new_node = DoublyLinkedListNode(new_data)
     if self.head.data == old_data:
         self.head.prev = new_node
         new_node.next = self.head
         self.head = new_node
     #otherwise
     else:
         current_node = self.head
         while current_node.next.data != old_data:
             current_node = current_node.next
             if current_node.next is None:
                 print "Node not in list"
                 return
         new_node.next = current_node.next
         current_node.next.prev = new_node
         current_node.next = new_node
         new_node.prev = current_node