Class: DataStructList::CycleSimpleLinkedList

Inherits:
SimpleLinkedList show all
Defined in:
lib/data_struct_list.rb

Instance Attribute Summary

Attributes inherited from Stack

#first, #head, #last

Instance Method Summary collapse

Methods inherited from SimpleLinkedList

#remove

Methods inherited from Stack

#initialize, #remove

Constructor Details

This class inherits a constructor from DataStructList::Stack

Instance Method Details

#find(id) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/data_struct_list.rb', line 111

def find(id)
  if @first == nil then return @first end

  elm = @first

  until elm == @last.next
    if elm.id == id then break end
    elm = elm.next
  end

  return elm
end

#insert(hash) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/data_struct_list.rb', line 124

def insert(hash)
  if @head.quant == 0 then
    @head.next = Node.new(hash)
    @first = @head.next
    @last = @head.next
    @head.quant += 1
    @first.next = @last

  else
    @last.next =  Node.new(hash)
    @last = @last.next
    @head.quant += 1
  end

  @last.next = @first

  return @last.id
end