Source code Algoritma Devide and conquer C++

Source code Algoritma Devide and conquer C++


using namespace std;
void quickSort(int numbers[], int array_size){
  q_sort(numbers, 0, array_size - 1);

// a recursive function that breaks down the problem into smaller ones
// until they are simple enough to solve directly
void q_sort(int numbers[], int left, int right){
  int pivot, l_hold, r_hold;

  l_hold = left;
  r_hold = right;
  pivot = numbers[left];
  while (left &lt; right){
    while ((numbers[right] &gt;= pivot) && (left &lt; right))
    if (left != right){
      numbers[left] = numbers[right];
    while ((numbers[left] &lt;= pivot) && (left &lt; right))
    if (left != right){
      numbers[right] = numbers[left];
  numbers[left] = pivot;
  pivot = left;
  left = l_hold;
  right = r_hold;
  if (left &lt; pivot)
    q_sort(numbers, left, pivot-1);
  if (right &gt; pivot)
    q_sort(numbers, pivot+1, right);

0 Response to "Source code Algoritma Devide and conquer C++"

Post a Comment