Class: DSA::LinkedList::Node
- Inherits:
-
Object
- Object
- DSA::LinkedList::Node
- Defined in:
- lib/dsa-ruby/linked_list.rb
Overview
Node for a singly linked list.
Instance Attribute Summary collapse
-
#next ⇒ Node?
The next node in the list.
-
#val ⇒ Object
The value stored in the node.
Instance Method Summary collapse
-
#initialize(val = 0, nxt = nil) ⇒ Node
constructor
Initialize a new singly linked list node.
Constructor Details
#initialize(val = 0, nxt = nil) ⇒ Node
Initialize a new singly linked list node.
19 20 21 22 |
# File 'lib/dsa-ruby/linked_list.rb', line 19 def initialize(val = 0, nxt = nil) @val = val @next = nxt end |
Instance Attribute Details
#next ⇒ Node?
Returns the next node in the list.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dsa-ruby/linked_list.rb', line 12 class Node attr_accessor :val, :next # Initialize a new singly linked list node. # # @param val [Object] the value to store # @param nxt [Node, nil] the next node (default: nil) def initialize(val = 0, nxt = nil) @val = val @next = nxt end end |
#val ⇒ Object
Returns the value stored in the node.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dsa-ruby/linked_list.rb', line 12 class Node attr_accessor :val, :next # Initialize a new singly linked list node. # # @param val [Object] the value to store # @param nxt [Node, nil] the next node (default: nil) def initialize(val = 0, nxt = nil) @val = val @next = nxt end end |