Class: Lista
- Inherits:
-
Object
- Object
- Lista
- Includes:
- Enumerable
- Defined in:
- lib/alu0100987522/lista.rb,
lib/alu0100987522/version.rb
Defined Under Namespace
Classes: Node
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
- #clasificar ⇒ Object
- #each ⇒ Object
- #pop_head ⇒ Object
- #pop_tail ⇒ Object
- #push_head(value) ⇒ Object
- #push_tail(value) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
5 6 7 |
# File 'lib/alu0100987522/lista.rb', line 5 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
5 6 7 |
# File 'lib/alu0100987522/lista.rb', line 5 def tail @tail end |
Instance Method Details
#clasificar ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/alu0100987522/lista.rb', line 68 def clasificar if(@head.value.sal >= 5) return true else return false end end |
#each ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/alu0100987522/lista.rb', line 86 def each x = @tail while(x != nil) yield x.value x = x.next end end |
#pop_head ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alu0100987522/lista.rb', line 34 def pop_head() if(@head == nil) return nil else aux = @head.value if(@head == @tail) @head = @head.prev @head, @tail = nil else @head = @head.prev @head.next = nil end return aux end end |
#pop_tail ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/alu0100987522/lista.rb', line 51 def pop_tail() if(@tail == nil) return nil else aux = @tail.value if(@head == @tail) @tail = @tail.next @head, @tail = nil else @tail = @tail.next @tail.prev = nil end return aux end end |
#push_head(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/alu0100987522/lista.rb', line 9 def push_head(value) if(@head == nil) @head = Node.new(value, nil, nil) @tail = head else nodo = Node.new(value, nil, @head) @head.next = nodo @head = nodo end end |
#push_tail(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alu0100987522/lista.rb', line 22 def push_tail(value) if(@tail == nil) @tail = Node.new(value, nil, nil) @head = tail else nodo = Node.new(value, @tail, nil) @tail.prev = nodo @tail = nodo end end |
#to_s ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/alu0100987522/lista.rb', line 76 def to_s str = @tail.value.to_s() aux = @tail.next while(aux) str << aux.value.to_s() aux = aux.next end return str end |