class Lista_doble
Lista_doble
class It's a double linked list in this case, we used a struct to describe the class too we include the mixin Enumerable
-
empty
-
initialize
-
each
Attributes
head[RW]
tail[RW]
Public Class Methods
new()
click to toggle source
We set the initial and last node to nil
# File lib/menud/lista.rb, line 86 def initialize() @head = nil @tail = nil end
Public Instance Methods
convert_a_each()
click to toggle source
# File lib/menud/lista.rb, line 169 def convert_a_each n_array= [] enum=@head for i in self do n_array.push(enum.value) enum = enum.next end n_array.bubbleach end
convert_a_for()
click to toggle source
# File lib/menud/lista.rb, line 152 def convert_a_for n_array= [] enum=@head for i in self do n_array.push(enum.value) enum = enum.next end n_array.bubblefor end
each() { |value| ... }
click to toggle source
Its a define like a iteration on the nodes of the list to get the value
# File lib/menud/lista.rb, line 143 def each enum = @head while (enum != nil) yield enum.value enum = enum.next end end
empty?()
click to toggle source
We set the initial node to nil and we see if the dll is empty
# File lib/menud/lista.rb, line 80 def empty? @head == nil end
extraer_elemento()
click to toggle source
We extract a new element on the double linked list
# File lib/menud/lista.rb, line 112 def extraer_elemento @nodo = Nodo_.new(nil, @head.value, nil) @head = @head.next @head.prev = nil return @nodo #nodo = @head #if @head.next == nil # @head = nil # else # @head = @head.next #end #return nodo #nodo = @head #@head = @head.next #nodo.next = nil #nodo.prev = nil #if @head == nil # @tail = nil #end #return nodo end
insertar_elemento(nodo)
click to toggle source
We insert a new element on the double linked list
# File lib/menud/lista.rb, line 93 def insertar_elemento(nodo) @nodo = Nodo_.new(nil, nodo, nil) if @tail == nil @head = @nodo @tail = @nodo #@nodo else @nodo.next = @head @head.prev = @nodo @head = @nodo #@nodo end end