data_structures.linked_list.deque_doubly

Implementing Deque using DoublyLinkedList … Operations:

  1. insertion in the front -> O(1)

  2. insertion in the end -> O(1)

  3. remove from the front -> O(1)

  4. remove from the end -> O(1)

Classes

LinkedDeque

A Private class (to be inherited)

_DoublyLinkedBase

A Private class (to be inherited)

Module Contents

class data_structures.linked_list.deque_doubly.LinkedDeque

Bases: _DoublyLinkedBase

A Private class (to be inherited)

add_first(element)

insertion in the front >>> LinkedDeque().add_first(‘AV’).first() ‘AV’

add_last(element)

insertion in the end >>> LinkedDeque().add_last(‘B’).last() ‘B’

first()

return first element >>> d = LinkedDeque() >>> d.add_first(‘A’).first() ‘A’ >>> d.add_first(‘B’).first() ‘B’

last()

return last element >>> d = LinkedDeque() >>> d.add_last(‘A’).last() ‘A’ >>> d.add_last(‘B’).last() ‘B’

remove_first()

removal from the front >>> d = LinkedDeque() >>> d.is_empty() True >>> d.remove_first() Traceback (most recent call last):

IndexError: remove_first from empty list >>> d.add_first(‘A’) # doctest: +ELLIPSIS <data_structures.linked_list.deque_doubly.LinkedDeque object at … >>> d.remove_first() ‘A’ >>> d.is_empty() True

remove_last()

removal in the end >>> d = LinkedDeque() >>> d.is_empty() True >>> d.remove_last() Traceback (most recent call last):

IndexError: remove_first from empty list >>> d.add_first(‘A’) # doctest: +ELLIPSIS <data_structures.linked_list.deque_doubly.LinkedDeque object at … >>> d.remove_last() ‘A’ >>> d.is_empty() True

class data_structures.linked_list.deque_doubly._DoublyLinkedBase

A Private class (to be inherited)

class _Node(link_p, element, link_n)
has_next_and_prev()
__slots__ = ('_prev', '_data', '_next')
_data
_next
_prev
__len__()
_delete(node)
_insert(predecessor, e, successor)
is_empty()
_header
_size = 0
_trailer