Class: DLinked::List::Node
- Inherits:
-
Object
- Object
- DLinked::List::Node
- Defined in:
- lib/d_linked/list/node.rb
Overview
Represents a single element within the Doubly Linked List.
Each node maintains three critical pieces of data:
-
The actual value stored by the user.
-
A pointer to the next node in the list.
-
A pointer to the previous node in the list.
This structure is the foundation of the list’s O(1) performance for boundary operations.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next ⇒ DLinked::List::Node?
A pointer to the subsequent node in the list, or nil if this is the tail.
-
#prev ⇒ DLinked::List::Node?
A pointer to the preceding node in the list, or nil if this is the head.
-
#value ⇒ Object
The actual data stored by the user in this node.
Instance Method Summary collapse
-
#initialize(value = nil, prev = nil, next_node = nil) ⇒ Node
constructor
Initializes a new Node instance.
Constructor Details
#initialize(value = nil, prev = nil, next_node = nil) ⇒ Node
Initializes a new Node instance.
35 36 37 38 39 |
# File 'lib/d_linked/list/node.rb', line 35 def initialize(value = nil, prev = nil, next_node = nil) @value = value @prev = prev @next = next_node end |
Instance Attribute Details
#next ⇒ DLinked::List::Node?
Returns A pointer to the subsequent node in the list, or nil if this is the tail.
24 25 26 |
# File 'lib/d_linked/list/node.rb', line 24 def next @next end |
#prev ⇒ DLinked::List::Node?
Returns A pointer to the preceding node in the list, or nil if this is the head.
28 29 30 |
# File 'lib/d_linked/list/node.rb', line 28 def prev @prev end |
#value ⇒ Object
Returns The actual data stored by the user in this node.
20 21 22 |
# File 'lib/d_linked/list/node.rb', line 20 def value @value end |