Class: List
Overview
Clase que implementa una lista
Instance Attribute Summary collapse
-
#end ⇒ Object
Returns the value of attribute end.
-
#tam ⇒ Object
Returns the value of attribute tam.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#each ⇒ Object
Función para ir sacando el valor de los nodos y compararlos con las funciones Enumerable.
-
#initialize ⇒ List
constructor
A new instance of List.
-
#pop ⇒ Object
sacar el nodo que se encuentre en la cabeza de la lista.
-
#pushend(entry) ⇒ Object
introducir nodo por la cola de la lista.
-
#pushtop(entry) ⇒ Object
introducir nodo por la cabeza de la lista.
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
5 6 7 8 9 |
# File 'lib/pract07/List.rb', line 5 def initialize @top = nil #cabeza de la lista @end = nil #cola de la lista @tam = nil #tamaño de la lista end |
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
3 4 5 |
# File 'lib/pract07/List.rb', line 3 def end @end end |
#tam ⇒ Object
Returns the value of attribute tam.
3 4 5 |
# File 'lib/pract07/List.rb', line 3 def tam @tam end |
#top ⇒ Object
Returns the value of attribute top.
3 4 5 |
# File 'lib/pract07/List.rb', line 3 def top @top end |
Instance Method Details
#<=>(other) ⇒ Object
56 57 58 |
# File 'lib/pract07/List.rb', line 56 def <=>(other) tam <=> other.tam end |
#each ⇒ Object
Función para ir sacando el valor de los nodos y compararlos con las funciones Enumerable
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pract07/List.rb', line 45 def each if @top.nil? return nil end entry = @top until entry.nil? yield entry.value entry = entry.next end end |
#pop ⇒ Object
sacar el nodo que se encuentre en la cabeza de la lista
35 36 37 38 39 40 41 |
# File 'lib/pract07/List.rb', line 35 def pop #sacar el nodo que se encuentre en la cabeza de la lista return nil if @top.nil? entry = @top @top = @top.next @tam -= 1 return entry end |
#pushend(entry) ⇒ Object
introducir nodo por la cola de la lista
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pract07/List.rb', line 23 def pushend(entry) #introducir nodo por la cola de la lista if @top.nil? @top = entry @end = entry @tam = 1 else @end.next = entry @end = entry @tam += 1 end end |
#pushtop(entry) ⇒ Object
introducir nodo por la cabeza de la lista
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pract07/List.rb', line 11 def pushtop(entry) #introducir nodo por la cabeza de la lista if @top.nil? @top = entry @end = entry @tam = 1 else entry.next = @top @top = entry @tam += 1 end end |