File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ using namespace std ;
4+
5+ void quicksort (int num[21 ],int first,int last){
6+ int i, j, pivot, temp;
7+
8+ if (first<last){
9+ pivot=first;
10+ i=first;
11+ j=last;
12+
13+ while (i<j){
14+ while (num[i]<=num[pivot]&&i<last)
15+ i++;
16+ while (num[j]>num[pivot])
17+ j--;
18+ if (i<j){
19+ temp=num[i];
20+ num[i]=num[j];
21+ num[j]=temp;
22+ }
23+ }
24+ temp=num[pivot];
25+ num[pivot]=num[j];
26+ num[j]=temp;
27+ quicksort (num,first,j-1 );
28+ quicksort (num,j+1 ,last);
29+
30+ }
31+ }
32+
33+ int main (){
34+ int i, count, num[21 ];
35+
36+ cout<<" Enter the number of elements you wanna enter: " ;
37+ cin>>count;
38+
39+ cout<<" Enter your " <<count<<" elements: " ;
40+ for (i=0 ;i<count;i++)
41+ cin>>num[i];
42+
43+ quicksort (num,0 ,count-1 );
44+
45+ cout<<" Quick Sorted elements: " ;
46+ for (i=0 ;i<count;i++)
47+ cout<<num[i]<<" ," ;
48+ return 0 ;
49+ }
You can’t perform that action at this time.
0 commit comments