class Listaa::Lista

Attributes

First[R]
Sz[R]

Public Class Methods

new() click to toggle source
# File lib/Lista/Lista.rb, line 8
def initialize
    @First = nil
    @Sz = 0
end

Public Instance Methods

at(i) click to toggle source
# File lib/Lista/Lista.rb, line 24
def at(i)
    @Aux = @First
    if(i<@Sz)
        for j in 1..i do
            @Aux = @Aux.next
        end
        @Aux.value
    else
        nil
    end
end
each() { |value| ... } click to toggle source
# File lib/Lista/Lista.rb, line 86
def each
    aux = @First
    while aux!=nil
        yield aux.value
        aux = aux.next
    end
end
iterarFirst(num) click to toggle source
# File lib/Lista/Lista.rb, line 62
def iterarFirst(num)
    if(num<@Sz)
        aux = @First
        for i in 0..num-1 do
            aux = aux.next
        end
        aux.value
    else
        nil
    end
end
iterarLast(num) click to toggle source
# File lib/Lista/Lista.rb, line 74
def iterarLast(num)
    if(num<@Sz)
        aux = @Last
        for i in 0..num-1 do
            aux = aux.prev
        end
        aux.value
    else
        nil
    end
end
push_back(objeto) click to toggle source
# File lib/Lista/Lista.rb, line 13
def push_back(objeto)
    if(@Sz==0)
        @First = Nodo.new(objeto,nil,nil)
        @Last = @First
    else
        @Last.next = Nodo.new(objeto,nil,@Last)
        @Last = @Last.next
    end
    @Sz = @Sz + 1
end
takeAt(i) click to toggle source
# File lib/Lista/Lista.rb, line 36
def takeAt(i)
    @Aux = @First
    if(i<@Sz)
        for j in 1..i-1 do
            @Aux = @Aux.next
        end
        @Aux2 = @Aux.next
        @Aux.next = @Aux2.next
        @Sz = @Sz -1
        @Aux2.value
    else
        nil
    end
end
takeFirst() click to toggle source
# File lib/Lista/Lista.rb, line 51
def takeFirst
    if(@Sz>=1)
        @Aux = @First
        @First = @First.next
        @Sz = @Sz -1
        @Aux.value
    else
        nil
    end
end
to_apa() click to toggle source
# File lib/Lista/Lista.rb, line 103
def to_apa
    a = []
    a = sort { |x,y| x <=> y }
    
    f=""
    a.collect{ |x| f=f+x.to_s+"\n"}
    f
end
to_s() click to toggle source
# File lib/Lista/Lista.rb, line 94
def to_s 
    a = []
    a = sort { |x,y| x <=> y }
    
    f=""
    a.collect{ |x| f=f+x.autorTo_s+"\n"}
    f
end