Quick Sort

Code Id 29
Date Updated 3/7/2010
Title Quick Sort  
Description
This program implements quick sort � a divide and conquer method.  In order to sort longer arrays, we first divide the array in two parts and then sort them individually.  
                                  
Codes Snippet
partition (int a[], int low, int high, int *point)
{
        int x, left, right, temp;
        x=a[low]; /* the algorithm is trying to find the proper position of x*/
        left = high;
        right = low + 1;
        while ( right < left) 
{
        while (a[right] <= x) && (right < left)
                right ++;
        while(a[left]>x)
                up--;
        if (right < left)
        { /*the two elements are on the wrong side interchange a[right] and a[left]*/
                temp = a[right];
                a[right] = a[left];
                a[left] = temp;
                right++;
                left -- ;
        }
}
/*interchange a[low] and a[left]*/
a[low]=a[left];
a[left]=x;
*point=left;
}

Comments are closed.