Esempio n. 1
0
def number_to_linked_list(n):
    head = None
    for i in str(n):
        tmp = Node(int(i))
        tmp.next = head
        head = tmp

    return head
Esempio n. 2
0
def reverse_list(head):
  new_head = None
  cur = head
  while cur:
    node = Node(cur.data)
    node.next = new_head
    new_head = node
    cur = cur.next

  return new_head
Esempio n. 3
0
    def test_a1(self):
        head = Node(1)
        head.next = Node(1)
        head.next.next = Node(2)
        head.next.next.next = Node(2)
        head.next.next.next.next = Node(2)
        head.next.next.next.next.next = Node(3)

        result = remove_dupes_a(head)
        self.assertEqual(result.toList(), [1, 2, 3])
Esempio n. 4
0
    def test_b3(self):
        head = Node(1)
        head.next = Node(1)

        result = remove_dupes_b(head)
        self.assertEqual(result.toList(), [1])