Class: Lista

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pr06/lista_d.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Returns a new instance of Lista



12
13
14
15
# File 'lib/pr06/lista_d.rb', line 12

def initialize
    @head=nil
    @tail=nil
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head



11
12
13
# File 'lib/pr06/lista_d.rb', line 11

def head
  @head
end

#tailObject (readonly)

Returns the value of attribute tail



11
12
13
# File 'lib/pr06/lista_d.rb', line 11

def tail
  @tail
end

Instance Method Details

#each {|@head| ... } ⇒ Object

Yields:



59
60
61
62
63
64
# File 'lib/pr06/lista_d.rb', line 59

def each

  yield @head
  yield @tail

end

#extract_headObject



44
45
46
47
48
49
50
# File 'lib/pr06/lista_d.rb', line 44

def extract_head
 if head ==nil
  puts "No hay nada que extraer"
else 
    lista.pop head
end
end

#extract_tailObject



52
53
54
55
56
57
58
# File 'lib/pr06/lista_d.rb', line 52

def extract_tail
    if head ==nil
     puts "No hay nada que extraer"
   else 
       lista.pop tail
   end
end

#insert(value) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pr06/lista_d.rb', line 18

def insert(value)
 if head ==nil
     head.Node.new(value,nil,nil)
     lista.push head
else 
    lista.push value
end
end

#insert_many(v1, v2, v3) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pr06/lista_d.rb', line 27

def insert_many(v1,v2,v3)
 if head ==nil
     head.Node.new(v1,nil,nil)
     @n1.Node.new(v2,nil,head)
     @n2.Node.new(v3,nil,@n1)
     lista.push head
      lista.push @n1
       lista.push @n2
     
else 
    lista.push v1
     lista.push v2
      lista.push v3
end
end