Added documentation to the Python Code
This commit is contained in:
parent
3ae086fb58
commit
9098da24c0
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user