def enqueue(self, value): new = Node(value) if self.head is None: self.head = new self.tail = new else: new.set_next(self.head) self.head = new
def add_followup(lst1, lst2): if len(lst1) < len(lst2): lst1, lst2 = lst2, lst1 for _ in range(len(lst1) - len(lst2)): h = lst2.get_head() n = Node(0) n.set_next(h) lst2.set_head(n) _sum(lst1.get_head(), lst2.get_head())
def reverse_linked_list(new_list, original_list): head = new_list p = original_list while (p != None): n = Node(p.get_data()) if (head == None): head = n else: n.set_next(head) head = n p = p.get_next() return head
def partition(lst, nodex): ''' Time Complexity = O(N) Space Complexity = O(1) ''' current = lst.get_head() prev = Node() if current.get_data() < nodex: prev = current current = current.get_next() while current != None: if current.get_data() < nodex: tmp = current current = current.get_next() prev.set_next(current) tmp.set_next(lst.get_head()) lst.set_head(tmp) else: prev = current current = current.get_next()