C Program To Implement The Quick Sorting Using Linear Array:
C program for Quick Sort. Quick Sort also known as Partition exchange  sort, is a comparison  unstable -in-place sorting algorithm.Quick Sort compare n items in  time complexity in average and best case, while takes   O(nlogn) O(n2) in worst case.
It comes under divide and conquer algorithm which divides the large set of array in small by picking up a pivot element as a reference element, and do sorting.



ALGORITHM:-

step 1 : start
step 2 : take input in array
step 3 : Select the highest index value has pivot
step 4 : Declare two variables to point left and right of the list
step 5 : left points to the lower index
step 6 : Right Points to the higher Index
step 7 : while left value is less than pivot then move it in rightside
step 8 : while right value is greater than pivot then move it in leftside
step 9 : if value of left and right is not match with pivot then swap left and right
step 10: if leftvalue ≥ rightvalue, the point where they met is new pivot
step 11: Print the Sorted Element of array
Step 12: Stop the Execution 



PROGRAM CODE:-

#include
#include

//quick Sort function to Sort Integer array list
void quicksort(int array[], int first, int last)
{

    int pivotIndex, temp, index1, index2;

    if(first < last)
    {
        pivot = first;
        index1 = first;
        index2 = last;

        //Perform Quick Sorting Method in Ascending Order
        while(index1 < index2)
        {
            while(array[index1] <= array[pivotIndex] && index1 < last)
            {
                index1++;
            }
            while(array[index2] > array[pivotIndex])
            {
                index2--;
            }

            if(index1 < index2)
            {
                temp = array[index1];
                array[index1] = array[index2];
                array[index2] = temp;
            }
        }

        temp = array[pivotIndex];
        array[pivotIndex] = array[index2];
        array[index2] = temp;

        //Recursive call the quick sort
        quicksort(array, first, index2-1);
        quicksort(array, index2+1, last);
    }
}

int main()
{
    int array[100],n,i;

    //Enter the number of element
    printf("Enter the number of element : ");
    scanf("%d",&n);

    //Enter the Element in Array
    printf("Enter Elements in the Array: ");
    for(i = 0; i < n; i++)
    {
        scanf("%d",&array[i]);
    }

    
    quick(array,0,n-1);

    //Array Element After sorted
    printf("Sorted elements: ");
    for(i = 0; i < n; i++)
    {
        printf(" %d",array[i]);
    }
    getch();
    return 0;
}


OUTPUT:-

Enter the Number or Element: 5
Enter the Element in the Array
0 0 -22 45 12

Sorted Element is
-22 0 0 12 45


C Program To Sort the Element of an array using Quick sort method.
How to sort the array element in ascending order using Quick Sort Technique.
Implementation of Quick Sort.


2 comments

Click here for comments