Parent

Class/Module Index [+]

Quicksearch

MatrizDensa

Clase que hereda de la clase matriz. Almacena matrices densas.

Attributes

mat[RW]

Array bidimensional que representa la matriz

Public Class Methods

new(f,c,e) click to toggle source

crea una matriz con n filas, m columnas y almacena los valores que se le pasan por parĂ¡metros

# File lib/matrices_p9.rb, line 233
def initialize(f,c,e) 

        super(f,c)
        @mat = Array.new(@fil.to_i){Array.new(@col.to_i)} #k2
       if (e != nil)
                #Rellenamos la matriz con lo valores recibidos 
               for i in (0...@fil.to_i)
                        for j in (0...@col.to_i)
                                @mat[i][j]=e[i*@col.to_i+j];
                        end
               end
       end
end

Public Instance Methods

<=>(other) click to toggle source

Operador de comparacion (Modulo comparable). se comparan por la suma de sus componentes.

# File lib/matrices_p9.rb, line 288
def <=> (other)
        return nil unless other.is_a?MatrizDensa
        c1=0
        c2=0
        for i in (0...@fil.to_i)
                for j in (0...@col.to_i)
                        if(self.mat[i][j] > other.mat[i][j])
                                c1+=1
                        elsif(self.mat[i][j] < other.mat[i][j])
                                c2+=1
                        end
                end
        end
        (c1)<=>(c2)
end
max() click to toggle source

funcion que calcula el mayor valor que se encuentra en la matriz

# File lib/matrices_p9.rb, line 258
def max
        m = self.mat[0][0]
        for i in (0...@fil.to_i)
                #for j in (0...@col.to_i)
                @col.to_i.times do |j| 
                                                
                        if (self.mat[i][j] > m)
                                m = self.mat[i][j]
                        end
                end
        end
        return m
end
min() click to toggle source

funcion que calcula el menor valor que se encuentra en la matriz

# File lib/matrices_p9.rb, line 273
def min
        m = self.mat[0][0]
        for i in (0...@fil.to_i)
                #for j in (0...@col.to_i)
                @col.to_i.times do |j| 
                        if (self.mat[i][j] < m)
                                m = self.mat[i][j]
                        end
                end
        end
        return m
end
pos(a,b) click to toggle source

Metodo getter que devuelve el valor de una posicion determinada

# File lib/matrices_p9.rb, line 248
def pos(a,b)
        @mat[a][b]
end
to_s() click to toggle source

Metodo que devuelve la matriz en forma de string

# File lib/matrices_p9.rb, line 253
def to_s    
        "#{@mat}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.