Class: LinkedList::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/linked_list_sourav.rb

Overview

this class defines one node the basic building blog of linked list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, forward = nil) ⇒ Node

intializes when new is invoked



6
7
8
9
10
# File 'lib/linked_list_sourav.rb', line 6

def initialize(data, forward = nil) #intializes when new is invoked
  @data = data
  @forward = forward
  self
end

Instance Attribute Details

#dataObject

data for holding data and forwards refers to next node



4
5
6
# File 'lib/linked_list_sourav.rb', line 4

def data
  @data
end

#forwardObject

data for holding data and forwards refers to next node



4
5
6
# File 'lib/linked_list_sourav.rb', line 4

def forward
  @forward
end

Instance Method Details

#to_sObject



12
13
14
15
16
# File 'lib/linked_list_sourav.rb', line 12

def to_s
  string = "Data: #{self.data} "
  string << "Points to: #{self.forward.data}" if self.forward
  string
end