The following are the steps to set up Quick Sort in Data Structures.
Note that in step 7, The swapping keeps the larger element to the right and smaller element to the left, relative to the pivot. Example:
Implementation of Quick sort # include<stdio.h> void Quick sort(int k[], int lb,int vb); void main() { int a[20]; int n,i; clrscr(); printf(“How many numbers:”); scanf(“%d”, &n); printf(“\n Enter the numbers: \n”); for(i=0;i<n;i++) { scanf(“%d”,a[i]); } quicksort(a,o,n-1); printf(“The following are the sorted elements :\n”); for(i=0;i<n;i++) { printf(“%d”,a[i]); } getch(); } void quick sort(int k[], int lb, int vb) { int flag; int i,j,key; flag=1; if(lb<ub) { int temp; i=lb+1; j=ub; key=k[lb]; while(flag) { while(k[i]<key && i<ub) i=i+1; While(k[j]>key && j>lb) j=j-1; if(i<j) { temp=k[j]; k[j]=k[i]; k[i]=temp; } else flag=0; } temp=k[lb]; k[lb]=k[j]; k[j]=temp; quicksort(k,lb,j-1); quicksort(k,j+1,ub); } }
How many numbers : Enter the numbers:
The running time of sorting algorithm is usually measured by the number f(n) of comparison required to sort ‘n’ elements, the quick sort algorithm which has many variations as been studied extensively generally speaking, The algorithm has a worst case running time of order n2/2=o(n2) it’s an average cape running time of order o(nlogn)
You liked the article?
Like : 0
Vote for difficulty
Current difficulty (Avg): Medium
1/15
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.
Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox