class Lista

Attributes

head[RW]

Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list

queue[RW]

Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list

tamanio[RW]

Includes the module Enumerable It have tres values, head of the list, queue of the list and size of the list

Public Class Methods

new() click to toggle source

@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

convertirArray(lista) click to toggle source

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
each() { |valor| ... } click to toggle source

return node

# File lib/prct06/lista.rb, line 202
def each
      aux = @head
      while aux != nil
          yield aux.valor
          aux = aux.siguiente
      end 
  end
empty() click to toggle source

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
insert_head(nodo) click to toggle source

@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
insert_plus(nodos, index) click to toggle source

@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
insert_queue(nodo) click to toggle source

@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
ordenandoEach(lista) click to toggle source

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
ordenandoSort(lista) click to toggle source
# File lib/prct06/lista.rb, line 185
def ordenandoSort(lista)
  auxiliar = lista.convertirArray(lista)
  auxiliar.sort
end
ordenarArray(lista) click to toggle source

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
pop_head() click to toggle source

@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
pop_queue() click to toggle source

@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
to_s() click to toggle source

@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