def add_to_head(self, item): new_node = Node() new_node.item = item if not self.head: self.head = new_node else: old_head = self.head new_node.next = old_head self.head = new_node
def add_to_head(self, item): new_node = Node() new_node.item = item if not self.head: self.head = new_node else: old_head = self.head new_node.next = old_head self.head = new_node
def add_to_tail(self, item): if not self.head: return self.add_to_head(item) current = self.head old_tail = current while (current): old_tail = current current = current.next new_tail = Node() new_tail.item = item old_tail.next = new_tail
def add_to_tail(self, item): if not self.head: return self.add_to_head(item) current = self.head old_tail = current while(current): old_tail = current current = current.next new_tail = Node() new_tail.item = item old_tail.next = new_tail