data_structures.linked_list.doubly_linked_list_two¶
- A linked list is similar to an array, it holds values. However, links in a linked
list do not have indexes.
This is an example of a double ended, doubly linked list.
Each link references the next link and the previous one.
- A Doubly Linked List (DLL) contains an extra pointer, typically called previous
pointer, together with next pointer and data which are there in singly linked list.
- Advantages over SLL - It can be traversed in both forward and backward direction.
Delete operation is more efficient
Classes¶
Functions¶
|
Module Contents¶
- class data_structures.linked_list.doubly_linked_list_two.LinkedList¶
- __contains__(value: int)¶
- __iter__()¶
- __str__()¶
- delete_value(value)¶
- get_head_data()¶
- get_tail_data()¶
- insert(value: int) None ¶
- insert_at_position(position: int, value: int) None ¶
- is_empty()¶
- head = None¶
- tail = None¶
- class data_structures.linked_list.doubly_linked_list_two.LinkedListIterator(head)¶
- __iter__()¶
- __next__()¶
- current¶
- class data_structures.linked_list.doubly_linked_list_two.Node(data: int, previous=None, next_node=None)¶
- __str__() str ¶
- get_data() int ¶
- get_next()¶
- get_previous()¶
- data¶
- next = None¶
- previous = None¶
- data_structures.linked_list.doubly_linked_list_two.create_linked_list() None ¶
>>> new_linked_list = LinkedList() >>> new_linked_list.get_head_data() is None True >>> new_linked_list.get_tail_data() is None True >>> new_linked_list.is_empty() True >>> new_linked_list.insert(10) >>> new_linked_list.get_head_data() 10 >>> new_linked_list.get_tail_data() 10 >>> new_linked_list.insert_at_position(position=3, value=20) >>> new_linked_list.get_head_data() 10 >>> new_linked_list.get_tail_data() 20 >>> new_linked_list.set_head(Node(1000)) >>> new_linked_list.get_head_data() 1000 >>> new_linked_list.get_tail_data() 20 >>> new_linked_list.set_tail(Node(2000)) >>> new_linked_list.get_head_data() 1000 >>> new_linked_list.get_tail_data() 2000 >>> for value in new_linked_list: ... print(value) 1000 10 20 2000 >>> new_linked_list.is_empty() False >>> for value in new_linked_list: ... print(value) 1000 10 20 2000 >>> 10 in new_linked_list True >>> new_linked_list.delete_value(value=10) >>> 10 in new_linked_list False >>> new_linked_list.delete_value(value=2000) >>> new_linked_list.get_tail_data() 20 >>> new_linked_list.delete_value(value=1000) >>> new_linked_list.get_tail_data() 20 >>> new_linked_list.get_head_data() 20 >>> for value in new_linked_list: ... print(value) 20 >>> new_linked_list.delete_value(value=20) >>> for value in new_linked_list: ... print(value) >>> for value in range(1,10): ... new_linked_list.insert(value=value) >>> for value in new_linked_list: ... print(value) 1 2 3 4 5 6 7 8 9