data_structures.linked_list.doubly_linked_list ============================================== .. py:module:: data_structures.linked_list.doubly_linked_list .. autoapi-nested-parse:: https://en.wikipedia.org/wiki/Doubly_linked_list Classes ------- .. autoapisummary:: data_structures.linked_list.doubly_linked_list.DoublyLinkedList data_structures.linked_list.doubly_linked_list.Node Functions --------- .. autoapisummary:: data_structures.linked_list.doubly_linked_list.test_doubly_linked_list Module Contents --------------- .. py:class:: DoublyLinkedList .. py:method:: __iter__() >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_head('b') >>> linked_list.insert_at_head('a') >>> linked_list.insert_at_tail('c') >>> tuple(linked_list) ('a', 'b', 'c') .. py:method:: __len__() >>> linked_list = DoublyLinkedList() >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> len(linked_list) == 5 True .. py:method:: __str__() >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_tail('a') >>> linked_list.insert_at_tail('b') >>> linked_list.insert_at_tail('c') >>> str(linked_list) 'a->b->c' .. py:method:: delete(data) -> str .. py:method:: delete_at_nth(index: int) >>> linked_list = DoublyLinkedList() >>> linked_list.delete_at_nth(0) Traceback (most recent call last): .... IndexError: list index out of range >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> linked_list.delete_at_nth(0) == 1 True >>> linked_list.delete_at_nth(3) == 5 True >>> linked_list.delete_at_nth(1) == 3 True >>> str(linked_list) '2->4' >>> linked_list.delete_at_nth(2) Traceback (most recent call last): .... IndexError: list index out of range .. py:method:: delete_head() .. py:method:: delete_tail() .. py:method:: insert_at_head(data) .. py:method:: insert_at_nth(index: int, data) >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_nth(-1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(1, 666) Traceback (most recent call last): .... IndexError: list index out of range >>> linked_list.insert_at_nth(0, 2) >>> linked_list.insert_at_nth(0, 1) >>> linked_list.insert_at_nth(2, 4) >>> linked_list.insert_at_nth(2, 3) >>> str(linked_list) '1->2->3->4' >>> linked_list.insert_at_nth(5, 5) Traceback (most recent call last): .... IndexError: list index out of range .. py:method:: insert_at_tail(data) .. py:method:: is_empty() >>> linked_list = DoublyLinkedList() >>> linked_list.is_empty() True >>> linked_list.insert_at_tail(1) >>> linked_list.is_empty() False .. py:attribute:: head :value: None .. py:attribute:: tail :value: None .. py:class:: Node(data) .. py:method:: __str__() .. py:attribute:: data .. py:attribute:: next :value: None .. py:attribute:: previous :value: None .. py:function:: test_doubly_linked_list() -> None >>> test_doubly_linked_list()