Quicksort is a divide and conquer algorithm Here In this article we are going to discuss about Quick sort algorithm with C Language programming language and Also we will learn about Types of Sorting Algorithm.
The steps are:
- Pick an element from the array elements, this element is called as pivot element.
- Divide the unsorted array of elements in two arrays with values less than the pivot come in the first sub array, while all elements with values greater than the pivot come in the second sub-array (equal values can go either way). This step is called the partition operation.
- Recursively repeat the step number-2(until the sub-arrays are sorted) to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values. The same logic we have implemented in the following C language program.
Time complexity of Quick Sort
- worst case time complexity O(n2)

Types of Sorting Algorithms:
Quicksort algorithm C Program implementation
#include<stdio.h>
void quicksort(int number[25],int first,int last){
int i, j, pivot, temp;
if(first<last){
pivot=first;
i=first;
j=last;
while(i<j){
while(number[i]<=number[pivot]&&i<last)
i++;
while(number[j]>number[pivot])
j--;
if(i<j){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
temp=number[pivot];
number[pivot]=number[j];
number[j]=temp;
quicksort(number,first,j-1);
quicksort(number,j+1,last);
}
}
int main(){
int i, count, number[25];
printf("How many elements YOU Wants to enter?: ");
scanf("%d",&count);
printf("Enter %d elements: ", count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
quicksort(number,0,count-1);
printf("Order of Sorted elements is: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
OUTPUT
How many elements YOU Wants to enter?: 5
Enter 5 Elements : 10,8,9,4,2
Order of Sorted elements is: 2,4,8,9,10
Additional Reading
- SEO Practices Everyone Should Follow SEO Rules
- Complete Top SEO Checklist
- Yoast Seo Premium 15.2 Nulled – WordPress SEO Plugin
- Top 50+ SEO Interview Questions
- What is a Backlink? How to Get More Backlinks
- TCS INTERVIEW QUESTIONS – CLICKE HERE
you can read more articles like this here.
READ MORE
If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.❤