class

LinkedList::Node(T)

Inherits Reference < Object

A node is the building block of linked lists consisting of a values and a pointer to the next node in the linked list.

To create a node:

node = Node.new(5)
puts node.value

The above produces:

5

Check the value of the node with #value. Get the next node in the list with #next.

Constructors

new(value : T)

Creates a node with the specified value.

new

Creates a node with no value.

Instance methods

next

Returns the next node in the linked list, or nil if it is the tail.

node = Node.new(1)
node.next = Node.new(2)
node.next.value # => 2
next=(next_node : Node(T) | Nil)

Sets the next node in the linked list to next_node

node = Node.new(1)
node.next = Node.new(2)
node.next.value # => 2
to_s(io)

Overloading the to_s function to print the contents of the node

value

Returns the value of the node, or nil if no value was supplied

Node.new(1).value # => 1