def test_partition_short(self):
     a = LinkedListNode(9)
     b = LinkedListNode(7)
     c = LinkedListNode(2)
     d = LinkedListNode(1)
     a.next = b
     b.next = c
     c.next = d
     h = partition_linked_list(a, 5)
     print(h, h.next.value, h.next.next.value, h.next.next.next.value)
def reverse_and_clone(node):
    prev = None
    while node is not None:
        current = LinkedListNode(node.value)
        current.next = prev
        prev = current
        node = node.next
    return prev
 def test_partition(self):
     a = LinkedListNode(9)
     b = LinkedListNode(7)
     c = LinkedListNode(6)
     d = LinkedListNode(5)
     e = LinkedListNode(4)
     f = LinkedListNode(3)
     g = LinkedListNode(2)
     # List 1: 679
     a.next = b
     b.next = c
     # List 2: 2345
     d.next = e
     e.next = f
     f.next = g
     # Sum:
     h = sum_lists(a, d)
     print(h.value, h.next.value, h.next.next.value, h.next.next.next.value)
Example #4
0
 def test_partition(self):
     a = LinkedListNode(9)
     b = LinkedListNode(7)
     c = LinkedListNode(6)
     d = LinkedListNode(5)
     e = LinkedListNode(4)
     f = LinkedListNode(3)
     g = LinkedListNode(2)
     # List 1: 679
     a.next = b
     b.next = c
     # List 2: 2345
     d.next = e
     e.next = f
     f.next = g
     # Sum:
     h = sum_lists(a, d)
     print(h.value, h.next.value, h.next.next.value, h.next.next.next.value)
 def test_sll_palindrome(self):
     a = LinkedListNode(9)
     b = LinkedListNode(7)
     c = LinkedListNode(6)
     d = LinkedListNode(5)
     e = LinkedListNode(6)
     f = LinkedListNode(7)
     g = LinkedListNode(9)
     # List 1: 679
     a.next = b
     b.next = c
     c.next = d
     d.next = e
     e.next = f
     f.next = g
     self.assertEqual(is_sll_palindrome_reverse(a), True)
 def test_partition(self):
     a = LinkedListNode(9)
     b = LinkedListNode(7)
     c = LinkedListNode(6)
     d = LinkedListNode(5)
     e = LinkedListNode(4)
     f = LinkedListNode(3)
     g = LinkedListNode(2)
     a.next = b
     b.next = c
     c.next = d
     d.next = e
     e.next = f
     f.next = g
     h = partition_linked_list(a, 5)
     fourh = h.next.next.next
     print(h.value, h.next.value, h.next.next.value, fourh.value, fourh.next.value,
           fourh.next.next.value, fourh.next.next.next.value)
Example #7
0
 def test_solution(self):
     a = LinkedListNode(1)
     b = LinkedListNode(2)
     c = LinkedListNode(3)
     d = LinkedListNode(4)
     e = LinkedListNode(5)
     f = LinkedListNode(6)
     g = LinkedListNode(7)
     a.next = b
     b.next = c
     c.next = d
     d.next = e
     e.next = f
     f.next = g
     solution(e)
     self.assertEqual(d.next.value, 6)
     self.assertEqual(d.next.next, g)
     self.assertEqual(f.next, g)