Class: LinkedList
Overview
Clase lista
Instance Attribute Summary collapse
-
#head ⇒ Object
Variables.
-
#tail ⇒ Object
Variables.
Instance Method Summary collapse
-
#add(value, *more) ⇒ Object
Añadir nodos a la lista.
- #each ⇒ Object
- #empty ⇒ Object
-
#initialize ⇒ LinkedList
constructor
Constructor.
-
#pop ⇒ Object
Saca la cabeza de la lista.
-
#to_s ⇒ Object
Mostrar la lista.
Constructor Details
#initialize ⇒ LinkedList
Constructor
15 16 17 |
# File 'lib/prct06/list.rb', line 15 def initialize @head = @tail = nil end |
Instance Attribute Details
#head ⇒ Object
Variables
11 12 13 |
# File 'lib/prct06/list.rb', line 11 def head @head end |
#tail ⇒ Object
Variables
11 12 13 |
# File 'lib/prct06/list.rb', line 11 def tail @tail end |
Instance Method Details
#add(value, *more) ⇒ Object
Añadir nodos a la lista
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prct06/list.rb', line 20 def add (value, *more) node = Node.new(value) @tail = node if @tail.nil? @head.next = node unless @head.nil? node.prev = @head unless @head.nil? @head = node more.each do |i| node2 = Node.new(i) @head.next = node2 node2.prev = @head @head = @head.next end end |
#each ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/prct06/list.rb', line 66 def each aux = @tail while aux != nil do yield aux.value aux = aux.next end end |
#empty ⇒ Object
46 47 48 49 50 51 |
# File 'lib/prct06/list.rb', line 46 def empty() emptyy = false emptyy = true if @head.nil? return emptyy end |
#pop ⇒ Object
Saca la cabeza de la lista
40 41 42 43 44 |
# File 'lib/prct06/list.rb', line 40 def pop() node = @head @head = @head.next return node end |
#to_s ⇒ Object
Mostrar la lista
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/prct06/list.rb', line 54 def to_s $i = @tail while ($i != nil) do puts "#{$i.value}" $i = $i.next end puts "CABEZA: #{@head.value}" puts "COLA: #{@tail.value}" end |