MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / Node

Class Node

data_structures/linked_list/singly_linked_list.py:9–37  ·  view source on GitHub ↗

Create and initialize Node class instance. >>> Node(20) Node(20) >>> Node("Hello, world!") Node(Hello, world!) >>> Node(None) Node(None) >>> Node(True) Node(True)

Source from the content-addressed store, hash-verified

7
8@dataclass
9class Node:
10 """
11 Create and initialize Node class instance.
12 >>> Node(20)
13 Node(20)
14 >>> Node("Hello, world!")
15 Node(Hello, world!)
16 >>> Node(None)
17 Node(None)
18 >>> Node(True)
19 Node(True)
20 """
21
22 data: Any
23 next_node: Node | None = None
24
25 def __repr__(self) -> str:
26 """
27 Get the string representation of this node.
28 >>> Node(10).__repr__()
29 'Node(10)'
30 >>> repr(Node(10))
31 'Node(10)'
32 >>> str(Node(10))
33 'Node(10)'
34 >>> Node(10)
35 Node(10)
36 """
37 return f"Node({self.data})"
38
39
40class LinkedList:

Callers 2

insert_nthMethod · 0.70

Calls

no outgoing calls

Tested by 1