/* Write C++ programs for sorting a given list of elements in ascending order using Quick sort sorting methods */
#include<iostream.h> #include<conio.h> int a[10],l,u,i,j; void quick(int *,int,int); void main() { clrscr(); cout <<"enter 10 elements"; for(i=0;i<10;i++) cin >> a[i]; l=0; u=9; quick(a,l,u); cout <<"sorted elements"; for(i=0;i<10;i++) cout << a[i] << " "; getch(); } void quick(int a[],int l,int u) { int p,temp; if(l<u) { p=a[l]; i=l; j=u; while(i<j) { while(a[i] <= p && i<j ) i++; while(a[j]>p && i<=j ) j--; if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp;} } temp=a[j]; a[j]=a[l]; a[l]=temp; cout <<"\n"; for(i=0;i<10;i++) cout <<a[i]<<" "; quick(a,l,j-1); quick(a,j+1,u); } } |
OUTPUT
enter 10 elements5 2 3 16 25 1 20 7 8 61 14
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 25 16 20 7 8 61
1 2 3 5 8 16 20 7 25 61
1 2 3 5 7 8 20 16 25 61
1 2 3 5 7 8 16 20 25 61
1 2 3 5 7 8 16 20 25 61
sorted elements1 2 3 5 7 8 16 20 25 61
what is logic of quick sort
quick sort generally…
i’m trying dis program but it doesnt working..
ya this code is working well and is very simple to understand also… thank u very much
one of the flower bracket is missing in the quick() function.
sorry ;i did not see the one close to temp;}
gud program!!!!!!!!!!!!!:)
good program of quicksort inc++
good….
Good and easy prog. . . .
A program by bubble sort method
very fuudu program
sale fudu bnayi jande ,,,,,ma di llun ina di,,,,sale chlda ha n program
repetition of numbers list in output
what is the code to sort letters in quick sort???tnx..
guys…..there is complete explanation i have seen for quick sort
Algorithm and Implementation Program of Quick Sort
http://geeksprogrammings.blogspot.com/2014/02/algorithm-quick-sort-program.html
thanks. but i need merge sort program with explanation…… ple
yeah not bad but sometime something missing becoz i m hacker so you need to prepare verry well either you gonna be hack
i’m from IIN chamanpura jay hind bhart matki jay vande matram
tum muje khoon do me tume aazadi dunga.
Inkalab Zindabad