ruby 1_ruby_quicksort.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 1_ruby_quicksort.rb相关的知识,希望对你有一定的参考价值。

# Use Gists to store entire functions
class QuickSort
 
  def self.sort!(keys)
    quick(keys,0,keys.size-1)
  end
 
  private
 
  def self.quick(keys, left, right)
    if left < right
      pivot = partition(keys, left, right)
      quick(keys, left, pivot-1)
      quick(keys, pivot+1, right)
    end
    keys
  end
 
  def self.partition(keys, left, right)
    x = keys[right]
    i = left-1
    for j in left..right-1
      if keys[j] <= x
        i += 1
        keys[i], keys[j] = keys[j], keys[i]
      end
    end
    keys[i+1], keys[right] = keys[right], keys[i+1]
    i+1
  end
 
end

以上是关于ruby 1_ruby_quicksort.rb的主要内容,如果未能解决你的问题,请参考以下文章

ruby sieve_1_prime_17.rb

ruby sieve_1_prime_13.rb

ruby sieve_1_prime_11.rb

ruby sieve_1_prime_7.rb

ruby sieve_1_prime_5.rb

ruby sieve_1_prime_3.rb