class Lista
Attributes
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list
Public Class Methods
@return Lista
type of the class @brief this method is for insert a new head at the list
# File lib/prct06/lista.rb, line 18 def initialize @head = nil @queue = nil @tamanio = 0 end
Public Instance Methods
return array @brief get a list this method convert that into an array param lista
# File lib/prct06/lista.rb, line 135 def convertirArray(lista) lista.map{ |y| y} end
return node
# File lib/prct06/lista.rb, line 202 def each aux = @head while aux != nil yield aux.valor aux = aux.siguiente end end
return true or false @brief tell the programmer if the list is empty or not
# File lib/prct06/lista.rb, line 193 def empty if tamanio == 0 true else false end end
@param nodo [Nodo] @return head of the node
# File lib/prct06/lista.rb, line 26 def insert_head(nodo) if empty nodo[:siguiente] = nil nodo[:anterior] = nil @head = nodo @queue = nodo else nodo[:siguiente] = @head @head[:anterior] = nodo nodo[:anterior] = nil @head = nodo end @tamanio = @tamanio + 1 end
@param nodo, index [Nodo], [Number] @return nodo @brief this method is for insert a new node at the list
# File lib/prct06/lista.rb, line 65 def insert_plus(nodos, index) #si el indice es 1, insertara por la cabeza if(index == 1) for i in 0..(nodos.length-1) insert_head(nodos[i]) end end #Si el indice es 2, insertara por la cola else if(index == 2) for i in 0..(nodos.length-1) insert_queue(nodos[i]) end end end
@param nodo [Nodo] @return queue of the node @brief the method is for insert a new queue at the list
# File lib/prct06/lista.rb, line 46 def insert_queue(nodo) if empty nodo[:siguiente] = nil nodo[:anterior] = nil @head = nodo @queue = nodo else nodo[:siguiente] = nil nodo[:anterior] = @queue @queue[:siguiente] = nodo @queue = nodo end @tamanio = @tamanio + 1 end
return array @brief get a list and return an array in order param lista
# File lib/prct06/lista.rb, line 163 def ordenandoEach(lista) auxiliar = lista.convertirArray(lista) indice = 0 auxiliar.each do |x| auxiliar.each do |y| if (indice < auxiliar.length-1) if (auxiliar[indice] > auxiliar[indice+1]) temporal = auxiliar[indice] auxiliar[indice] = auxiliar[indice+1] auxiliar[indice+1] = temporal end end indice = indice+1 end indice = 0 end return auxiliar end
# File lib/prct06/lista.rb, line 185 def ordenandoSort(lista) auxiliar = lista.convertirArray(lista) auxiliar.sort end
return array @brief get a list and return an array in order param lista
# File lib/prct06/lista.rb, line 143 def ordenarArray(lista) auxiliar = lista.convertirArray(lista) for i in 0..(auxiliar.length)do for j in 0..(auxiliar.length-2) do if auxiliar[j] > auxiliar[j+1] temporal = auxiliar[j] auxiliar[j] = auxiliar[j+1] auxiliar[j+1] = temporal end end end return auxiliar end
@return head of the list @brief return the head of the list and pass the second value at the position of the head
# File lib/prct06/lista.rb, line 82 def pop_head if !empty if @head == @queue aux = @head @head = nil @queue = nil else aux = @head @head = @head.siguiente @head[:anterior] = nil end @tamanio = @tamanio -1 aux end end
@return queue of the list @brief return the queue of the list and pass the penultimate value at the position of the head
# File lib/prct06/lista.rb, line 102 def pop_queue if !empty if @queue == @head aux = @queue @head = nil @queue = nil else aux = @queue @queue =aux.anterior @queue[:siguiente] = nil end @tamanio = @tamanio - 1 aux end end
@return [String] the resulting of join all the information, value, next and previous
# File lib/prct06/lista.rb, line 120 def to_s aux = @head s = "" while aux.siguiente != nil s += aux.valor.to_s + "\n" aux = aux.siguiente end s += aux.valor.to_s end