sorts an int array into an increasing order using the method quicksort - C Data Structure

C examples for Data Structure:Sort

Description

sorts an int array into an increasing order using the method quicksort


void qsort(int w[], int left, int right)
{
  int j, last;
  void swap(int w[], int j, int k);
  if(left >= right)
    return;
  swap(w, left, (left + right)/2);
  last = left;
  for(j = left + 1; j <= right; j++)
    if(w[j] < w[left])
      swap(w, ++last, j);
  swap(w, left, last);
  qsort(w, left, last - 1);
  qsort(w, last+1, right);
}
void swap(int w[], int j, int k)
{
  int temp;
  temp = w[j];
  w[j] = w[k];
  w[k] = temp;
}

Related Tutorials