Module grscheller.datastructures.nodes.dl

Doubly link nodes for graph-based data structures.

Classes

class DL_Node (left: Optional[DL_Node[_T]], data: _T, right: Optional[DL_Node[_T]])

Class for doubly link nodes for graph-like data structures.

  • this type of node always contain data, even if that data is None
  • more than one node can point to the same node forming bush like graphs
  • circular graphs are possible
  • doubly link lists possible
  • recursive binary trees possible
Expand source code
class DL_Node(Generic[_T]):
    """Class for doubly link nodes for graph-like data structures.

    * this type of node always contain data, even if that data is None
    * more than one node can point to the same node forming bush like graphs
    * circular graphs are possible
    * doubly link lists possible
    * recursive binary trees possible
    """
    __slots__ = '_data', '_left', '_right'

    def __init__(self, left: Optional[DL_Node[_T]], data: _T, right: Optional[DL_Node[_T]]):
        self._data = data
        self._left = left
        self._right = right

    def __bool__(self) -> bool:
        """Doubly linked nodes always contain data.

        * always returns true
        * this type of node always contain data, even if that data is None
        """
        return True

Ancestors

  • typing.Generic