class List
Gestionar una Lista enlazada
Attributes
head[RW]
head para cabecera tail para cola
tail[RW]
head para cabecera tail para cola
Public Class Methods
new()
click to toggle source
Constructor
# File lib/bibliografia/lista_impl.rb, line 28 def initialize @head = nil @tail = nil end
Public Instance Methods
extract_first()
click to toggle source
Extrae primer elemento
# File lib/bibliografia/lista_impl.rb, line 76 def extract_first e = @head @head = e.next e end
ins_end(value)
click to toggle source
Insertar un nodo al final de la lista
# File lib/bibliografia/lista_impl.rb, line 49 def ins_end(value) if @tail != nil n = Node.new(value, nil) @tail.next = n @tail = n else @head = Node.new(value, nil) @tail = @head end end
ins_start(value)
click to toggle source
Inserta un nodo al principio de la lista
# File lib/bibliografia/lista_impl.rb, line 34 def ins_start(value) if @head != nil && @head.next != nil n = @head @head = Node.new(value, n) elsif @head != nil n = @head @head = Node.new(value, n) @tail = n else @head = Node.new(value, nil) @tail = @head end end
length()
click to toggle source
NĂºmero de nodos de una lista
# File lib/bibliografia/lista_impl.rb, line 61 def length if @head == nil num = 0 else n = @head num = 1 while n.next != nil num += 1 n = n.next end end num end