Class: Lista

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/referencia/lista.rb

Direct Known Subclasses

ListaHija

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Constructor



6
7
8
9
10
# File 'lib/referencia/lista.rb', line 6

def initialize
  @inicio = Node.new(nil)
  @fin = Node.new(nil)
  @tamanio = 0
end

Instance Attribute Details

#finObject

Returns the value of attribute fin.



4
5
6
# File 'lib/referencia/lista.rb', line 4

def fin
  @fin
end

#inicioObject

Returns the value of attribute inicio.



4
5
6
# File 'lib/referencia/lista.rb', line 4

def inicio
  @inicio
end

#tamanioObject

Returns the value of attribute tamanio.



4
5
6
# File 'lib/referencia/lista.rb', line 4

def tamanio
  @tamanio
end

Instance Method Details

#eachObject



76
77
78
79
80
81
82
# File 'lib/referencia/lista.rb', line 76

def each
  aux =self.inicio
  while aux.next != nil do
    yield aux.value
    aux = aux.next
  end
end

#extraerPrimerElementoObject

Extrae el primer elemento de la lista



65
66
67
68
69
# File 'lib/referencia/lista.rb', line 65

def extraerPrimerElemento
 @tamanio = @tamanio-1
  @inicio = @inicio.next

end

#extraerUltimoElementoObject

Extrae el Ășltimo elemento de la lista



71
72
73
74
75
# File 'lib/referencia/lista.rb', line 71

def extraerUltimoElemento
  @tamanio = @tamanio-1
  @fin = @fin.previus
  @fin.next = nil
end

#insertar_final(*a_elemento) ⇒ Object

Inserta uno o varios elementos por el final (cabeza)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/referencia/lista.rb', line 12

def insertar_final(*a_elemento)
  a_elemento.each do |elemento|
    a_aux = Node.new(nil)
    a_aux.value = elemento

    if(@inicio.value == nil)
      @inicio = a_aux
      @fin = a_aux
    else
      a_aux.previus = @fin
      @fin.next = a_aux
      @fin = a_aux
    end
    @tamanio=@tamanio+1
  end
end

#insertar_inicio(*a_elemento) ⇒ Object

Inserta uno o varios elementos por el principio (cola)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/referencia/lista.rb', line 29

def insertar_inicio(*a_elemento)
  a_elemento.each do |elemento|
    a_aux = Node.new(nil)
    a_aux.value=elemento

    if(@inicio.value == nil)
      @inicio = a_aux
      @fin = a_aux
      @tamanio=@tamanio+1
    else
      a_aux.next = @inicio
      @inicio.previus = a_aux
      @inicio = a_aux
    end
    @tamanio = @tamanio+1
  end
end

#mostar_fin_inicioObject

Muestra la lista desde el final hasta el principio



56
57
58
59
60
61
62
63
# File 'lib/referencia/lista.rb', line 56

def mostar_fin_inicio
  aux = @fin
  p @fin.value
  while aux.previus  do
    aux = aux.previus
    p aux.value
  end
end

#mostar_inicio_finObject

Muestra la lista desde el inicio hasta el final



47
48
49
50
51
52
53
54
# File 'lib/referencia/lista.rb', line 47

def mostar_inicio_fin
  aux = @inicio
  p @inicio.value
  while aux.next  do
    aux = aux.next
    p aux.value
  end
end