Class: Lista
Instance Attribute Summary collapse
-
#cola ⇒ Object
Returns the value of attribute cola.
-
#head ⇒ Object
Returns the value of attribute head.
-
#nodo_actual ⇒ Object
Returns the value of attribute nodo_actual.
Instance Method Summary collapse
- #each ⇒ Object
-
#extract ⇒ Object
eliminar el nodo y cambiar los valores al nodo anterior.
- #extract_final ⇒ Object
-
#initialize(head, cola) ⇒ Lista
constructor
A new instance of Lista.
- #insert(x) ⇒ Object
- #insert_multiple(nodos) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(head, cola) ⇒ Lista
Returns a new instance of Lista.
9 10 11 12 |
# File 'lib/dieta/lista.rb', line 9 def initialize(head,cola) @head = head @cola = cola end |
Instance Attribute Details
#cola ⇒ Object
Returns the value of attribute cola.
7 8 9 |
# File 'lib/dieta/lista.rb', line 7 def cola @cola end |
#head ⇒ Object
Returns the value of attribute head.
7 8 9 |
# File 'lib/dieta/lista.rb', line 7 def head @head end |
#nodo_actual ⇒ Object
Returns the value of attribute nodo_actual.
7 8 9 |
# File 'lib/dieta/lista.rb', line 7 def nodo_actual @nodo_actual end |
Instance Method Details
#each ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dieta/lista.rb', line 51 def each while @head != @cola yield @head.value @head=@head.prev end if @head == @cola if @head == nil nil else yield @cola.value end end end |
#extract ⇒ Object
eliminar el nodo y cambiar los valores al nodo anterior
39 40 41 |
# File 'lib/dieta/lista.rb', line 39 def extract() @cola=@cola.next end |
#extract_final ⇒ Object
43 44 45 |
# File 'lib/dieta/lista.rb', line 43 def extract_final() @head = @head.prev end |
#insert(x) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dieta/lista.rb', line 14 def insert(x) node = Nodo.new(x,nil,nil) if @head==nil && @cola==nil node.prev = @cola node.next = @head @nodo_actual = node @head = node @cola = node else node.prev = @head node.next = nil @nodo_actual = node @head.next = node @head = node end end |
#insert_multiple(nodos) ⇒ Object
32 33 34 35 36 |
# File 'lib/dieta/lista.rb', line 32 def insert_multiple(nodos) nodos.each do |nd| insert(nd) end end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/dieta/lista.rb', line 47 def to_s @head.to_s end |