Class: DLinked::List::Node

Inherits:
Object
  • Object
show all
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:

  1. The actual value stored by the user.

  2. A pointer to the next node in the list.

  3. 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

CacheList::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, prev = nil, next_node = nil) ⇒ Node

Initializes a new Node instance.

Parameters:

  • value (Object, nil) (defaults to: nil)

    The value to store in the node.

  • prev (DLinked::List::Node, nil) (defaults to: nil)

    The node preceding this one.

  • next_node (DLinked::List::Node, nil) (defaults to: nil)

    The node succeeding this one.



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

#nextDLinked::List::Node?

Returns A pointer to the subsequent node in the list, or nil if this is the tail.

Returns:

  • (DLinked::List::Node, nil)

    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

#prevDLinked::List::Node?

Returns A pointer to the preceding node in the list, or nil if this is the head.

Returns:

  • (DLinked::List::Node, nil)

    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

#valueObject

Returns The actual data stored by the user in this node.

Returns:

  • (Object)

    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