Ruby快速排序法

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

def partition(data, front, back)
  lastS1 = front
  pivot = data[front]
  frontUnknown = front + 1
  
  while frontUnknown <= last do
    if data[frontUnknown] < pivot
      backS1 += 1
      data.swap(frontUnknown, backS1)
    end

    frontUnknown += 1
  end

  data.swap(front, backS1)
  backS1
end


def quicksort(data, front = 0, back = data.size - 1)
  if front < back 
    pivotIndex = partition(data, front, back)
    quicksort(data, front, pivotIndex - 1)
    quicksort(data, pivotIndex + 1, back)
  end
end