data_structures.linked_list.doubly_linked_list¶
https://en.wikipedia.org/wiki/Doubly_linked_list
Classes¶
Functions¶
|
Module Contents¶
- class data_structures.linked_list.doubly_linked_list.DoublyLinkedList¶
- __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')
- __len__()¶
>>> linked_list = DoublyLinkedList() >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) >>> len(linked_list) == 5 True
- __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'
- delete(data) str ¶
- 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
- delete_head()¶
- delete_tail()¶
- insert_at_head(data)¶
- 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
- insert_at_tail(data)¶
- is_empty()¶
>>> linked_list = DoublyLinkedList() >>> linked_list.is_empty() True >>> linked_list.insert_at_tail(1) >>> linked_list.is_empty() False
- head = None¶
- tail = None¶
- class data_structures.linked_list.doubly_linked_list.Node(data)¶
- __str__()¶
- data¶
- next = None¶
- previous = None¶
- data_structures.linked_list.doubly_linked_list.test_doubly_linked_list() None ¶
>>> test_doubly_linked_list()