Esempio n. 1
0
    def test_something(self):
        l1_node1 = Node(2)
        l1_node2 = Node(4)
        l1_node3 = Node(3)

        l1_node1.next_node = l1_node2
        l1_node2.next_node = l1_node3

        l2_node1 = Node(5)
        l2_node2 = Node(6)
        l2_node3 = Node(4)

        l2_node1.next_node = l2_node2
        l2_node2.next_node = l2_node3

        l3_node1 = Node(7)
        l3_node2 = Node(0)
        l3_node3 = Node(8)

        l3_node1.next_node = l3_node2
        l3_node2.next_node = l3_node3

        result = add_two_numbers(l1_node1, l2_node1)

        self.assertEqual(result.value, l3_node1.value)
        self.assertEqual(result.next_node.value, l3_node2.value)
        self.assertEqual(result.next_node.next_node.value, l3_node3.value)
    def test_something(self):
        node1 = Node(1)
        node2 = Node(2)
        node3 = Node(3)
        node4 = Node(4)
        node5 = Node(5)

        node1.next_node = node2
        # node2.next_node = node3
        # node3.next_node = node4
        # node4.next_node = node5

        remove_nth_from_end(node1, 2)

        self.assertEqual(True, False)
Esempio n. 3
0
    def insert_at_head(self, data):
        """
        Given the object, data
        Then increment the linked list size by one
        And create a new node using the object, data

        When the head is not currently assigned (self.head == None)
        Then assign the newly created node to the head node
        When the head does have a valid object reference
        Then link the newly created node as the head (new_node = self.head)

        Performance: O(1)

        :param data: the object that the node will hold
        """
        self.size = self.size + 1
        new_node = Node(data)

        if self.head is not None:
            # link the new node to the current head
            new_node.next_node = self.head

        # assign the head position to the new node
        self.head = new_node