src.pydasa.structs.lists.ndlt#

Module to represent the Node data structure for the Linked List and Doubly Linked List in PyDASA.

Classes:

Node: Base class for creating Single Linked List Node or SLNode and Double Linked List Node or DLNode. SLNode: Implements a single linked list node with data and next node reference. DLNode: Implements a double linked list node with data, next node, and previous node references.

IMPORTANT: based on the implementations proposed by the following authors/books:

# . Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne. # . Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser.

Classes#

Node

Node base class for creating Single Linked List Node or SLNode and Double Linked List Node or DLNode. Fundamental for the Linked List and Doubly Linked List data structures.

SLNode

SLNode class for creating a Single Linked List Node. Inherits from the Node class. Fundamental for the Linked List data structure.

DLNode

DLNode class for creating a Double Linked List Node. Inherits from the SLNode class. Fundamental for the Doubly Linked List data structure.

Module Contents#

class src.pydasa.structs.lists.ndlt.Node#

Bases: Generic[pydasa.structs.types.generics.T]

Node base class for creating Single Linked List Node or SLNode and Double Linked List Node or DLNode. Fundamental for the Linked List and Doubly Linked List data structures.

Parameters:

Generic (T) – Generic type for a Python data structure.

Returns:

A node object with the following attributes:
  • _data: The data stored in the node.

Return type:

Node

_data: pydasa.structs.types.generics.T | None = None#

data stored in the node. By default, it is set to None.

_error_handler(err)#

_error_handler() function that handles the errors that can occur in the Node.

if an error occurs in SingleLinkedList, it formats the error according to the context (package/module/class), the function (method) that generated it, and sends it to the upper component in the DataStruct hierarchy to handle it as the user considers appropriate.

Parameters:

err (Exception) – Exception that occurred in the Node.

Return type:

None

_validate_type(elm)#

_validate_type() function that checks if the type of the element is the same as the type of the Node.

Parameters:
  • elm (Optional[T]) – element to be processed in the Node.

  • T (-) – Type of the element to be processed in the Node.

Raises:

TypeError – error if the type of the element to be added is not the same as the type of the elements already contained in the Node.

Returns:

True if the type of the element is the same as the type of the Node. False otherwise.

Return type:

bool

property data: pydasa.structs.types.generics.T#

data Property to read the data in the Node. Acts as a getter (get()) for the _data attribute.

Returns:

data stored in the Node.

Return type:

T

class src.pydasa.structs.lists.ndlt.SLNode#

Bases: Node[pydasa.structs.types.generics.T]

SLNode class for creating a Single Linked List Node. Inherits from the Node class. Fundamental for the Linked List data structure.

Parameters:
  • Node (dataclass) – Node base class for creating single and double linked nodes.

  • Generic (T) – Generic type for a Python data structure.

Returns:

A single linked node object with the following attributes:
  • _data: The data stored in the node.

  • _next: The next node of the same type.

Return type:

SLNode

_next: SLNode[T] | None = None#

next node of the same type. By default, it is set to None.

property next: SLNode[T] | None#

next() Property to read the next node in the list. Acts as a getter (get()) for the _next attribute.

Returns:

reference to the next node of the list. If there is no next node, it returns None.

Return type:

Optional[“SLNode[T]”]

class src.pydasa.structs.lists.ndlt.DLNode#

Bases: SLNode[pydasa.structs.types.generics.T]

DLNode class for creating a Double Linked List Node. Inherits from the SLNode class. Fundamental for the Doubly Linked List data structure.

Parameters:
  • SLNode (dataclass) – SLNode class for creating a single linked list node.

  • Generic (T) – Generic type for a Python data structure.

Returns:

A double linked node object with the following attributes:
  • _data: The data stored in the node.

  • _next: The next node of the same type.

  • _prev: The previous node of the same type.

Return type:

DLNode

_prev: DLNode[T] | None = None#
property prev: DLNode[T] | None#

prev() Property to read the previous node in the list. Acts as a getter (get()) for the _prev attribute.

Returns:

reference to the previous node of the list.

Return type:

node (Optional[“DLNode[T]”])