FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-algorithims/MergeSort.java at main · faraimtb/java-algorithims · GitHub
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
faraimtb
/
java-algorithims
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
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
java-algorithims
/
MergeSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (40 loc) · 1.11 KB
Breadcrumbs
java-algorithims
/
MergeSort.java
Copy path
File metadata and controls
45 lines (40 loc) · 1.11 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
package
com
.
ematrix
;
import
java
.
sql
.
Array
;
import
java
.
util
.
Arrays
;
import
java
.
util
.
Random
;
public
class
MergeSort
{
/* Java program for Merge Sort */
public
void
merge
(
int
[]
sOne
,
int
[]
sTwo
,
int
[]
S
){
int
i
=
0
;
int
j
=
0
;
while
(
i
+
j
<
S
.
length
){
if
(
j
==
sTwo
.
length
||(
i
<
sOne
.
length
&&(
sOne
[
i
]<
sTwo
[
j
]))){
S
[
j
+
i
]=
sOne
[
i
++];
}
else
{
S
[
j
+
i
]=
sTwo
[
j
++];
}
}
}
public
void
sort
(
int
[]
S
){
if
(
S
.
length
<
2
){
return
;
}
int
mid
=
S
.
length
/
2
;
int
[]
sOne
=
Arrays
.
copyOfRange
(
S
,
0
,
mid
);
int
[]
sTwo
=
Arrays
.
copyOfRange
(
S
,
mid
,
S
.
length
);
sort
(
sOne
);
sort
(
sTwo
);
merge
(
sOne
,
sTwo
,
S
);
}
public
static
void
main
(
String
[]
args
){
int
[]
ary
=
new
int
[
10000000
];
Random
rand
=
new
Random
();
rand
.
setSeed
(
927838837377388388L
);
for
(
int
x
=
0
;
x
<
10000000
;
x
++)
ary
[
x
]=
rand
.
nextInt
(
10000000
);
MergeSort
mergeSort
=
new
MergeSort
();
mergeSort
.
sort
(
ary
);
for
(
int
item
:
ary
)
System
.
out
.
print
(
item
+
","
);
}
}
Back
|
FazBrowse Home
|
New Git URL