p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual C++ (http://p2p.wrox.com/forumdisplay.php?f=88)
-   -   Quick Sort in C Code (http://p2p.wrox.com/showthread.php?t=66347)

yulin11 March 3rd, 2008 03:49 AM

Quick Sort in C Code
 
Reference:http://www.codeuu.com/Quicksort
Code:

void quickSort(int numbers[], int array_size)
{
  q_sort(numbers, 0, array_size - 1);
}
 
 
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 < right)
  {
    while ((numbers[right] >= pivot) && (left < right))
      right--;
    if (left != right)
    {
      numbers[left] = numbers[right];
      left++;
    }
    while ((numbers[left] <= pivot) && (left < right))
      left++;
    if (left != right)
    {
      numbers[right] = numbers[left];
      right--;
    }
  }
  numbers[left] = pivot;
  pivot = left;
  left = l_hold;
  right = r_hold;
  if (left < pivot)
    q_sort(numbers, left, pivot-1);
  if (right > pivot)
    q_sort(numbers, pivot+1, right);
}

everyone can go far!www.codeuu.com

mindcoder March 11th, 2013 10:51 PM

that works cool
 
thanks, your algo works beautifully, i have been through few other codes they were all taking function arguments not liked by me

Good work [:)]

RobertGreene June 13th, 2018 05:27 AM

C Coding
 
Great Job , Actually I am seeking for the exact C code that you have been mentioned in this forum post,although it works great keep updating more thanks


All times are GMT -4. The time now is 11:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.