FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code/Algorithm/quickSort.java at master · dwipam/code · GitHub
dwipam
/
code
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
code
/
Algorithm
/
quickSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
62 lines (47 loc) · 1.42 KB
Breadcrumbs
code
/
Algorithm
/
quickSort.java
Copy path
File metadata and controls
executable file
·
62 lines (47 loc) · 1.42 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
package
quicksort
;
public
class
quickSort
{
private
int
array
[];
private
int
length
;
public
void
sort
(
int
[]
inputArr
) {
this
.
array
=
inputArr
;
length
=
inputArr
.
length
;
quickSort
(
0
,
length
-
1
);
}
private
void
quickSort
(
int
lowerIndex
,
int
higherIndex
) {
int
i
=
lowerIndex
;
int
j
=
higherIndex
;
int
pivot
=
array
[
lowerIndex
+(
higherIndex
-
lowerIndex
)/
2
];
while
(
i
<=
j
) {
while
(
array
[
i
] <
pivot
) {
i
++;
}
while
(
array
[
j
] >
pivot
) {
j
--;
}
if
(
i
<=
j
) {
exchangeNumbers
(
i
,
j
);
i
++;
j
--;
}
}
if
(
lowerIndex
<
j
)
quickSort
(
lowerIndex
,
j
);
if
(
i
<
higherIndex
)
quickSort
(
i
,
higherIndex
);
}
private
void
exchangeNumbers
(
int
i
,
int
j
) {
int
temp
=
array
[
i
];
array
[
i
] =
array
[
j
];
array
[
j
] =
temp
;
}
public
static
void
main
(
String
a
[])
{
quickSort
sorter
=
new
quickSort
();
int
[]
input
= {
5
,
8
,
10
,
1
,
4
,
2
,
7
,
15
,
11
,
9
};
sorter
.
sort
(
input
);
for
(
int
i
:
input
){
System
.
out
.
print
(
i
);
System
.
out
.
print
(
" "
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL