Esempio n. 1
0
 def setUp(self):
     self.__dll_1 = DoubleLinkedList()
     self.__dll_2 = DoubleLinkedList()
     for element in range(10, 16):
         self.__dll_1.append(element)
     for element in range(10, 13):
         self.__dll_2.append(element)
Esempio n. 2
0
 def setUp(self):
     self.__dll_1 = DoubleLinkedList()
     self.__dll_2 = DoubleLinkedList()
     for element in range(0, 4):
         self.__dll_1.top(element)
     for element in range(4, 7):
         self.__dll_2.top(element)
Esempio n. 3
0
    def test_union_empty_ll(self):
        dll_1 = DoubleLinkedList()
        dll_2 = DoubleLinkedList()
        u_dll = union(dll_1, dll_2)

        # Empty linked list. returns empty list
        self.assertEqual(u_dll.to_list(), [])
        print(u_dll.to_list())

        # Linked lists are None
        self.assertIsNone(union(None, None))
        print(union(None, None))
Esempio n. 4
0
def intersection(dll_1, dll_2):
    if dll_1 is None or dll_2 is None or dll_1.size() == 0 or dll_2.size(
    ) == 0:
        return None

    inter_dll = DoubleLinkedList()
    copy_dll_1 = DoubleLinkedList()
    for element in dll_1:
        copy_dll_1.append(element)

    for element in dll_2:
        if element in copy_dll_1:
            inter_dll.append(element)
            copy_dll_1.remove_element(element)
    return inter_dll
Esempio n. 5
0
    def test_empty_lists(self):
        dll_1 = DoubleLinkedList()
        dll_2 = DoubleLinkedList()

        # Empty lists, there is no intersection. Returns None
        self.assertIsNone(intersection(dll_1, dll_2))
        print(intersection(dll_1, dll_2))

        # None input, returns None
        self.assertIsNone(intersection(None, None))
        print(intersection(None, None))

        # If one list is empty there is no intersection. Returns None
        self.assertIsNone(intersection(dll_1, self.__dll_2))
        self.assertIsNone(intersection(self.__dll_1, dll_2))
        print(intersection(dll_1, self.__dll_2))
        print(intersection(self.__dll_1, dll_2))

        # if one list is None there is no intersection. Returns None
        self.assertIsNone(intersection(None, self.__dll_2))
        self.assertIsNone(intersection(self.__dll_1, None))
        print(intersection(None, self.__dll_2))
        print(intersection(self.__dll_1, None))
Esempio n. 6
0
def union(dll_1, dll_2):
    if dll_1 is None and dll_2 is None:
        return None
    if dll_1.size == 0:
        return dll_2
    elif dll_2.size == 0:
        return dll_1
    elif dll_1.size == 0 and dll_2.size == 0:
        return list()

    union_dll = DoubleLinkedList()
    for element in dll_2:
        union_dll.append(element)
    for element in dll_1:
        union_dll.append(element)
    return union_dll
Esempio n. 7
0
 def __init__(self, initial_size=10):
     self.bucket = [DoubleLinkedList() for _ in range(initial_size)]
     self.prime = 123
     self.num_entries = 0
Esempio n. 8
0
 def __init__(self):
     self.__dll = DoubleLinkedList()
     self.__last_block = None
Esempio n. 9
0
 def setUp(self):
     self.__value = 2
     self.__node = Node(1)
     self.__dll = DoubleLinkedList()