FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Data-Structures-Algorithms/Sorting/quicksort.cpp at master · priteshtripathi7/Data-Structures-Algorithms · GitHub
priteshtripathi7
/
Data-Structures-Algorithms
Public
forked from
CodersForLife/Data-Structures-Algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Data-Structures-Algorithms
/
Sorting
/
quicksort.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
49 lines (47 loc) · 808 Bytes
Breadcrumbs
Data-Structures-Algorithms
/
Sorting
/
quicksort.cpp
Copy path
File metadata and controls
executable file
·
49 lines (47 loc) · 808 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
include
<
iostream
>
using
namespace
std
;
int
comp=
0
;
int
Partition
(
int
a[],
int
p,
int
q)
{
int
x=a[p];
int
i=p,temp;
for
(
int
j=p+
1
;j<=q;j++)
{
if
(a[j]<=x)
{
i++;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[i];
a[i]=x;
a[p]=temp;
for
(
int
c=
0
;c<
6
;c++)
cout<<a[c]<<
"
\t
"
;
cout<<endl;
return
i;
}
void
Quicksort
(
int
a[],
int
p,
int
q)
{
if
(p<q)
{
comp=comp+q-p;
cout<<comp;
int
r=
Partition
(a,p,q);
Quicksort
(a,p,r-
1
);
Quicksort
(a,r+
1
,q);
}
}
int
main
()
{
int
n,a[
10000
];
cin>>n;
for
(
int
i=
0
;i<n;i++)
cin>>a[i];
Quicksort
(a,
0
,n-
1
);
for
(
int
i=
0
;i<n;i++)
cout<<a[i];
cout<<endl<<
"
final answer
"
<<comp;
}
Back
|
FazBrowse Home
|
New Git URL