Class: ListaDoble
- Inherits:
-
Object
- Object
- ListaDoble
- Includes:
- Enumerable
- Defined in:
- lib/menu_dietetico/lista.rb
Overview
CLase que representa una lista doblemente enlazada
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
- #empty ⇒ Object
- #extract_head ⇒ Object
- #extract_tail ⇒ Object
-
#initialize ⇒ ListaDoble
constructor
A new instance of ListaDoble.
- #insert_head(node) ⇒ Object
- #insert_muchos(nodes) ⇒ Object
- #insert_tail(node) ⇒ Object
Constructor Details
#initialize ⇒ ListaDoble
Returns a new instance of ListaDoble.
10 11 12 13 |
# File 'lib/menu_dietetico/lista.rb', line 10 def initialize() @head = nil @tail = nil end |
Instance Attribute Details
#head ⇒ Object (readonly)
Returns the value of attribute head.
8 9 10 |
# File 'lib/menu_dietetico/lista.rb', line 8 def head @head end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
8 9 10 |
# File 'lib/menu_dietetico/lista.rb', line 8 def tail @tail end |
Instance Method Details
#each ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/menu_dietetico/lista.rb', line 85 def each node = @head while(node != nil) yield node.value node = node.next end end |
#empty ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/menu_dietetico/lista.rb', line 15 def empty() vacio = false if (@head == nil) vacio = true elsif vacio == false end return vacio end |
#extract_head ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/menu_dietetico/lista.rb', line 47 def extract_head() if (empty()) return nil elsif node = @head @head = @head.next node.next = nil node.prev = nil return node.value end end |
#extract_tail ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/menu_dietetico/lista.rb', line 59 def extract_tail() if (empty()) return nil elsif node = @tail @tail = @tail.prev if (@tail) @tail.next = nil elsif @head == nil end node.next = nil node.prev = nil return node.value end end |
#insert_head(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/menu_dietetico/lista.rb', line 25 def insert_head(node) if (empty()) @head = node @tail = @head elsif @head.prev = node node.next = @head @head = node end end |
#insert_muchos(nodes) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/menu_dietetico/lista.rb', line 76 def insert_muchos(nodes) i=0 total=nodes.length while i<total do insert_head(nodes[i]) i=i+1 end end |
#insert_tail(node) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/menu_dietetico/lista.rb', line 36 def insert_tail(node) if (empty()) @head = node @tail = @head elsif @tail.next = node node.prev = @tail @tail = node end end |