Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/prct06/array.rb

Instance Method Summary collapse

Instance Method Details

#sort_eachObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prct06/array.rb', line 19

def sort_each
  
  @aux = self
  @pos = 0

  @aux.each do |x|
    @pos = @pos + 1
    @aux[@pos..@aux.length-1] do |y|
      if (x>y)
        x, y = y, x
      end
    end
  end
end

#sort_forObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/prct06/array.rb', line 3

def sort_for

  @aux = self

  for x in 0..self.length-1
    for y in 0..length-2-x
      if ( @aux[y] > @aux[y+1] )
        @aux[y], @aux[y+1] = @aux[y+1], @aux[y] 
      end
    end
  end

  return @aux

end