Class: Lista

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLista

Returns a new instance of Lista



10
11
12
# File 'lib/lista.rb', line 10

def initialize()
    @cabeza,@cola = nil
end

Instance Attribute Details

#cabezaObject (readonly)

Returns the value of attribute cabeza



8
9
10
# File 'lib/lista.rb', line 8

def cabeza
  @cabeza
end

#colaObject (readonly)

Returns the value of attribute cola



8
9
10
# File 'lib/lista.rb', line 8

def cola
  @cola
end

Instance Method Details

#each {|aux.value| ... } ⇒ Object

Yields:

  • (aux.value)


14
15
16
17
18
19
20
21
# File 'lib/lista.rb', line 14

def each
    aux = @cabeza
    while aux != @cola do
        yield aux.value
        aux = aux.next
    end
    yield aux.value
end

#pop_firstObject



40
41
42
# File 'lib/lista.rb', line 40

def pop_first()
    @cabeza = @cabeza.next
end

#pop_lastObject



44
45
46
# File 'lib/lista.rb', line 44

def pop_last()
   @cola = @cola.prev 
end

#push(other) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lista.rb', line 23

def push(other)
    if @cabeza == nil
        @cabeza = other
        other.next = @cabeza
        other.prev = @cabeza
        @cola = other
    end    
    
    if @cabeza != nil
        other.next = @cabeza
        other.prev = @cola
        @cola.next = other
        @cabeza.prev = other
        @cola = other
    end
end