Node
In a linked list, a node represents a unit of data. Each node occupies a separate location in memory, which means that a unique memory address is assigned to each node. If we examine the structure of a node, we can find the data it holds and a pointer(next) element that points to the next node.
class Node:
def __init__(self, data):
self.data = data
self.next = None
Creat Nodes
Assume that the memory address of the left node is '1202243114115' and the memory address of the right node is '1202243112121'. If the pointer of the left node which holds the data 'zun' stores the memory address '1202243112121' of the right node, this is the link. and it is through this link that a single linked list is formed.
node1 = Node("zun")
node2 = Node([1, 2])
Link Nodes: Liked List
In this case, the left node becomes the head, while the right node becomes the tail, as it has no subsequent nodes to connect to. Since there is no next node pointed to by the last node's pointer, the next property is set to None instead of a memory address. This structure makes it clear where the end of the linked list is.
zun -> [1, 2] -> None
'Basics' 카테고리의 다른 글
Stack, Queue, Deque? What the? (0) | 2024.11.25 |
---|---|
Understanding Time Complexity: No String Concatenation! (0) | 2024.11.18 |
Arrays in Python: Is the starting index 0 or 1? (3) | 2024.11.04 |
Data Types in Python with Examples (5) | 2024.10.28 |
What is the Data Structure? (6) | 2024.10.21 |