Class: Lista
- Inherits:
-
Object
- Object
- Lista
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/NutrientesEdu/Lista.rb,
lib/NutrientesEdu/version.rb
Direct Known Subclasses
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
Instance Method Summary collapse
- #each ⇒ Object
- #pop_head ⇒ Object
- #pop_tail ⇒ Object
- #push_head(value) ⇒ Object
- #push_tail(value) ⇒ Object
- #sort_salt ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
9 10 11 |
# File 'lib/NutrientesEdu/Lista.rb', line 9 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
9 10 11 |
# File 'lib/NutrientesEdu/Lista.rb', line 9 def tail @tail end |
Instance Method Details
#each ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/NutrientesEdu/Lista.rb', line 97 def each x = @head while(x != nil) yield x.value x = x.next end end |
#pop_head ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/NutrientesEdu/Lista.rb', line 37 def pop_head() if(@head == nil) return nil else val= @head node = @head.next @head = node if @head != nil @head.prev = nil end return val end end |
#pop_tail ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/NutrientesEdu/Lista.rb', line 51 def pop_tail() if(@tail == nil) return nil else val = @tail node = @tail.prev @tail = node if @tail != nil @tail.next = nil end return val end end |
#push_head(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/NutrientesEdu/Lista.rb', line 11 def push_head(value) if(@head == nil) node=Node.new(value,nil,nil) @head = node @tail = node else node=Node.new(value,@head,nil) @head.prev = node @head = node end end |
#push_tail(value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/NutrientesEdu/Lista.rb', line 25 def push_tail(value) if(@tail == nil) node=Node.new(value,nil,nil) @head = node @tail = node else node=Node.new(value,nil,@tail) @tail.next = node @tail = node end end |
#sort_salt ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/NutrientesEdu/Lista.rb', line 65 def sort_salt v = [] j = 0 each do |i| v[j] = i j += 1 end terminado = false while !terminado terminado = true for k in 0..(v.length)-2 if v[k].sal > v[k+1].sal aux = v[k+1] v[k+1] = v[k] v[k] = aux terminado = false end end end listadef = Lista.new() for k in 0..(v.length)-1 listadef.push_tail(v[k]) end return listadef end |
#to_s ⇒ Object
91 92 93 94 95 |
# File 'lib/NutrientesEdu/Lista.rb', line 91 def to_s s = "" each {|i| s += "#{i.to_s}\n"} s end |