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
+ using namespace std ;
3
+ int comp=0 ;
4
+ int Partition (int a[],int p,int q)
5
+ {
6
+
7
+ int x=a[p];
8
+ int i=p,temp;
9
+ for (int j=p+1 ;j<=q;j++)
10
+ {
11
+ if (a[j]<=x)
12
+ {
13
+ i++;
14
+ temp=a[i];
15
+ a[i]=a[j];
16
+ a[j]=temp;
17
+ }
18
+ }
19
+ temp=a[i];
20
+ a[i]=x;
21
+ a[p]=temp;
22
+ for (int c=0 ;c<6 ;c++)
23
+ cout<<a[c]<<" \t " ;
24
+ cout<<endl;
25
+ return i;
26
+ }
27
+ void Quicksort (int a[],int p,int q)
28
+ {
29
+ if (p<q)
30
+ {
31
+ comp=comp+q-p;
32
+ cout<<comp;
33
+ int r=Partition (a,p,q);
34
+ Quicksort (a,p,r-1 );
35
+ Quicksort (a,r+1 ,q);
36
+ }
37
+
38
+ }
39
+ int main ()
40
+ {
41
+ int n,a[10000 ];
42
+ cin>>n;
43
+ for (int i=0 ;i<n;i++)
44
+ cin>>a[i];
45
+ Quicksort (a,0 ,n-1 );
46
+ for (int i=0 ;i<n;i++)
47
+ cout<<a[i];
48
+ cout<<endl<<" final answer" <<comp;
49
+ }
You can’t perform that action at this time.
0 commit comments