Class: Lista_doble

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/biblio/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista_doble

Returns a new instance of Lista_doble.



46
47
48
49
50
# File 'lib/biblio/list.rb', line 46

def initialize()
   
   @head = nil
   @tail = nil 
end

Instance Attribute Details

#headObject

Returns the value of attribute head.



39
40
41
# File 'lib/biblio/list.rb', line 39

def head
  @head
end

#tailObject

Returns the value of attribute tail.



39
40
41
# File 'lib/biblio/list.rb', line 39

def tail
  @tail
end

Instance Method Details

#each(&block) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/biblio/list.rb', line 79

def each
    enum = @head
    while (enum != nil) 
         yield enum.value
         enum = enum.next
    end
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/biblio/list.rb', line 41

def empty?
   
   @head == nil
end

#extraer_elementoObject



69
70
71
72
73
74
75
76
77
# File 'lib/biblio/list.rb', line 69

def extraer_elemento
    
    @node = Node_.new(nil, @head.value, nil)
    
    @head = @head.next
    @head.prev = nil
    return @node
     
end

#insertar_elemento(node) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/biblio/list.rb', line 52

def insertar_elemento(node)
   
   @node =  Node_.new(nil, node, nil)
   
   if @tail == nil
      @head = @node
      @tail = @node
      #@node
   else
       @node.next = @head
       @head.prev = @node
       @head = @node
       #@node
   end
   
end

#ordenar!Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/biblio/list.rb', line 87

def ordenar! 
		cambio = true
		while cambio
cambio = false
i = @head
i_1 = @head.next
while i_1 != nil
	if(i.value > i_1.value)
		i.value, i_1.value = i_1.value, i.value
		cambio = true
	end
	i = i_1
	i_1 = i_1.next
end
		end
end

#to_sObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/biblio/list.rb', line 104

def to_s
	actual = @head
	cadena = "|"
		while !actual.nil?
			cadena << actual.value.to_s

			if !actual.next.nil?
				cadena << ", "
			end

			actual = actual.next
		end
	cadena << "|"
	return cadena
end