Esempio n. 1
0
def test_size():
    linked_list = DoublyLinkedList()
    assert linked_list.size() == 0

    linked_list.append(1)
    assert linked_list.size() == 1
    assert get_multi_node_list().size() == 4
Esempio n. 2
0
def test_append():
    doubly_linked_list = DoublyLinkedList()
    doubly_linked_list.append(3)
    doubly_linked_list.append(4)
    assert doubly_linked_list.size() == 2
    assert doubly_linked_list.get(0) == 3
    assert doubly_linked_list.get(1) == 4
Esempio n. 3
0
def get_multi_node_list() -> DoublyLinkedList:
    multi_node_list = DoublyLinkedList()
    multi_node_list.append(5)
    multi_node_list.append(2)
    multi_node_list.append(4)
    multi_node_list.append(1)
    return multi_node_list
Esempio n. 4
0
class QueueLinkedList(Generic[T]):
    """
    Queue backed by a doubly linked list
    """
    def __init__(self):
        self.linked_list = DoublyLinkedList()

    def __len__(self):
        return self.linked_list.size()

    # O(1)
    def dequeue(self) -> T:
        return self.linked_list.remove(0)

    # O(1)
    def enqueue(self, element: T):
        self.linked_list.append(element)
Esempio n. 5
0
def test_init():
    linked_list = DoublyLinkedList()
    linked_list.append(3)
    assert linked_list.size() == 1
    assert linked_list.get(0) == 3
Esempio n. 6
0
def test_append_empty():
    doubly_linked_list = DoublyLinkedList()
    doubly_linked_list.append(1)
    assert doubly_linked_list.size() == 1
    assert doubly_linked_list.get(0) == 1