From 9098da24c05a3e8a17775b0f77d014c06dc994cb Mon Sep 17 00:00:00 2001 From: Donald Calloway Date: Tue, 7 Oct 2025 18:04:10 -0700 Subject: [PATCH] Added documentation to the Python Code --- linked_list.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/linked_list.py b/linked_list.py index d3e63c3..bb60ecb 100644 --- a/linked_list.py +++ b/linked_list.py @@ -1,7 +1,41 @@ +""" + Module for singly and doubly linked list implementations with nodes storing 2D point data. + Classes: + -------- + Node: + Represents a node in a linked list, storing an index and a tuple of (x, y) coordinates. + Attributes: + index (int): The index of the node. + data (tuple): Tuple containing x and y integer coordinates. + prev (Node): Reference to the previous node (for doubly linked lists). + next (Node): Reference to the next node. + LinkedList: + Singly linked list implementation for storing 2D points. + Methods: + __init__(x: int, y: int): Initializes the list with a starting point. + append(x: int, y: int): Appends a new node with (x, y) at the end. + insert(index: int, x: int, y: int): Inserts a new node at the specified index. + delete(index: int): Deletes the node at the specified index. + to_list(): Returns a list of all (x, y) tuples in the list. + display_forward(): Prints the list from head to tail. + DoublyLinkedList: + Doubly linked list implementation for storing 2D points. + Methods: + __init__(): Initializes an empty doubly linked list. + append(x: int, y: int): Appends a new node with (x, y) at the end. + insert(index: int, x: int, y: int): Inserts a new node at the specified index. + delete(x: int, y: int): Deletes the first node with the specified (x, y) data. + reverse(): Reverses the order of the list in place. + find(data: tuple): Returns the index of the node with the specified data, or -1 if not found. + to_list(): Returns a list of all (x, y) tuples in the list. + display_forward(): Prints the list from head to tail. + display_backward(): Prints the list from tail to head. +""" + class Node: def __init__(self, index, x:int, y:int): self.index = index - self.data = (x, y) + self.data = (x, y) # Data as points or tuples of integral x-y coordinates self.prev = None self.next = None