dsa.doublylinkedlist module — ucxdsa documentation

# dsa.doublylinkedlist module

Module containing doubly linked list class.

class dsa.doublylinkedlist.DoublyLinkedList(head=None, tail=None, count=0)

  Bases: `LinkedList`

  A doubly linked list implementation. Inherits several methods from singly linked list, except for methods that modify the the contents of the list.

  append(value)

    Place a value at the end of the doubly linked list.

    Parameters:

      value – The value to append to the doubly linked list.

  delete(value)

    Delete the first occurrence of a value in the doubly linked list.

    Parameters:

      value – The value to be deleted.

    Raises:

      ValueError – If the value is not found.

  delete_head()

    Delete the head node of the doubly linked list.

    Raises:

      IndexError – If linked list is empty.

  delete_tail()

    Delete the tail node of the doubly linked list.

    Raises:

      IndexError – If linked list is empty.

  classmethod from_list(mylist)

    Create a doubly linked list from a list.

    Parameters:

      mylist (`list`) – A list or container to convert from.

    Returns:

      Doubly linked list with the contents of the list.

  insert_after(after_value, value)

    Insert a value after a specified value. Raise exception if value is not found.

    Parameters:

      - after_value – The value to insert after.

      - value – The value to append.

    Returns:

      None

    Raises:

      ValueError – If value is not found.

  prepend(value)

    Place a value at the beginning of the doubly linked list.

    Parameters:

      value – The value to prepend to the doubly linked list.

  to_list()

    Create a list with contents of the doubly linked list.

    Return type:

      `list`

    Returns:

      A list with contents of the doubly linked list.

  traverse_reverse()

    Print the contents of the doubly linked list in reverse order.

class dsa.doublylinkedlist.Node(value)

  Bases: `object`

  A doubly linked list node implementation.

  next

    reference to the next node

  prev

    reference to the previous node

  value

    value of the node