class DataStructList::CycleSimpleLinkedList
Public Instance Methods
find(id)
click to toggle source
# 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)
click to toggle source
# 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
remove(id)
click to toggle source
# File lib/data_struct_list.rb, line 143 def remove(id) elm = @first aux = @first until elm == nil if elm.id == id then break end aux = elm elm = elm.next end if elm!=nil then aux.next = elm.next @head.quant -= 1 if elm == @head.next @first = elm.next @head.next = @first end if @last == elm then @last = aux end elm = nil end end