Class: DS::ListElement
- Inherits:
-
Object
- Object
- DS::ListElement
- Defined in:
- lib/ds/lists/list_element.rb
Overview
Container for linked lists elements.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#next ⇒ Object
Returns the value of attribute next.
Instance Method Summary collapse
-
#append(x) ⇒ Object
Adds new element to list.
-
#initialize(x = nil) ⇒ ListElement
constructor
A new instance of ListElement.
-
#tail? ⇒ Boolean
Checks if given element is last.
Constructor Details
#initialize(x = nil) ⇒ ListElement
Returns a new instance of ListElement.
8 9 10 11 |
# File 'lib/ds/lists/list_element.rb', line 8 def initialize(x=nil) @data = x @next= nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/ds/lists/list_element.rb', line 6 def data @data end |
#next ⇒ Object
Returns the value of attribute next.
6 7 8 |
# File 'lib/ds/lists/list_element.rb', line 6 def next @next end |
Instance Method Details
#append(x) ⇒ Object
Adds new element to list.
14 15 16 17 |
# File 'lib/ds/lists/list_element.rb', line 14 def append(x) elem = ListElement.new(x) self.next = elem end |
#tail? ⇒ Boolean
Checks if given element is last.
20 21 22 |
# File 'lib/ds/lists/list_element.rb', line 20 def tail? @next.nil? end |