FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/MergeSort.java at main · Eggy115/Java · GitHub
Eggy115
/
Java
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5
Star
3
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
MergeSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (23 loc) · 914 Bytes
Breadcrumbs
Java
/
MergeSort.java
Copy path
File metadata and controls
26 lines (23 loc) · 914 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
import
java
.
util
.
Arrays
;
public
class
MergeSort
{
public
static
void
main
(
String
[]
args
) {
int
[]
arr
= {
38
,
27
,
43
,
3
,
9
,
82
,
10
};
System
.
out
.
println
(
"Unsorted array: "
+
Arrays
.
toString
(
arr
));
mergeSort
(
arr
,
0
,
arr
.
length
-
1
);
System
.
out
.
println
(
"Sorted array: "
+
Arrays
.
toString
(
arr
));
}
public
static
void
mergeSort
(
int
[]
arr
,
int
left
,
int
right
) {
if
(
left
<
right
) {
int
mid
= (
left
+
right
) /
2
;
mergeSort
(
arr
,
left
,
mid
);
mergeSort
(
arr
,
mid
+
1
,
right
);
merge
(
arr
,
left
,
mid
,
right
);
}
}
public
static
void
merge
(
int
[]
arr
,
int
left
,
int
mid
,
int
right
) {
int
[]
temp
=
new
int
[
right
-
left
+
1
];
int
i
=
left
,
j
=
mid
+
1
,
k
=
0
;
while
(
i
<=
mid
&&
j
<=
right
) {
if
(
arr
[
i
] <=
arr
[
j
]) {
temp
[
k
++] =
arr
[
i
++];
}
Back
|
FazBrowse Home
|
New Git URL