Class: Lista

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/Ein/p7.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Returns a new instance of Lista.



7
8
9
10
11
12
# File 'lib/Ein/p7.rb', line 7

def initialize
    
   @head = nil
   @tail = nil
    
end

Instance Attribute Details

#headObject

Returns the value of attribute head.



4
5
6
# File 'lib/Ein/p7.rb', line 4

def head
  @head
end

#tailObject

Returns the value of attribute tail.



4
5
6
# File 'lib/Ein/p7.rb', line 4

def tail
  @tail
end

Instance Method Details

#clasificar_lista_salObject



74
75
76
77
78
79
80
81
# File 'lib/Ein/p7.rb', line 74

def clasificar_lista_sal

   while(empty? != true) do
        puts get_tail.value.clasificar_sal
        
   end
   true
end

#eachObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/Ein/p7.rb', line 84

def each
    
   it = @head
   
   while it != nil
   
       yield it.value
       it = it.next
   end


end

#empty?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
# File 'lib/Ein/p7.rb', line 67

def empty?
    
    @head == nil
    @tail == nil

end

#get_headObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/Ein/p7.rb', line 47

def get_head

    aux = @head
    @head = @head.next
    #@head.prev = nil
    #aux.next = nil
    aux
    

end

#get_tailObject



58
59
60
61
62
63
64
65
# File 'lib/Ein/p7.rb', line 58

def get_tail

    aux = @tail
    @tail = @tail.prev
   # @tail.next = nil
#    aux.prev = nil
    aux
end

#set_head(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Ein/p7.rb', line 14

def set_head(value)
   nodo = Node.new(value, nil, nil)
   
   if(@head== nil)
       @head = nodo
       @tail = nodo
           
   else
    
    @head.prev = nodo
    nodo.next = @head
    @head = nodo
   end
   
   
    
end

#set_tail(value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/Ein/p7.rb', line 32

def set_tail(value)
    nodo = Node.new(value, nil, nil)
    
    if(@tail == nil)
        @head = nodo
        @tail = nodo
    else
        
        @tail.next = nodo
        nodo.prev = @tail
        @tail = nodo
    end

end