FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Basic/Practic.java at javaMain · pattjoshi/Java-Basic · GitHub
pattjoshi
/
Java-Basic
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
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-Basic
/
Practic.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (54 loc) · 1.5 KB
Breadcrumbs
Java-Basic
/
Practic.java
Copy path
File metadata and controls
61 lines (54 loc) · 1.5 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
public
class
Practic
{
public
static
void
PrintArray
(
int
arr
[]) {
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++) {
System
.
out
.
print
(
arr
[
i
] +
" "
);
}
System
.
out
.
println
();
}
// margeSort
public
static
void
margeSort
(
int
arr
[],
int
si
,
int
ei
) {
if
(
si
>=
ei
) {
return
;
}
// Kaam
int
mid
=
si
+ (
ei
-
si
) /
2
;
margeSort
(
arr
,
si
,
mid
);
// Left
margeSort
(
arr
,
mid
+
1
,
ei
);
// Rigt
marge
(
arr
,
si
,
mid
,
ei
);
}
public
static
void
marge
(
int
arr
[],
int
si
,
int
mid
,
int
ei
) {
// Temparary array
int
temp
[] =
new
int
[
ei
-
si
+
1
];
// Iteration decleare
int
i
=
si
;
// Left Iteration
int
j
=
mid
+
1
;
// Rtght Iteration
int
k
=
0
;
// temp Iteration
while
(
i
<=
mid
&&
j
<=
ei
) {
if
(
arr
[
i
] <
arr
[
j
]) {
temp
[
k
] =
arr
[
i
];
i
++;
}
else
{
temp
[
k
] =
arr
[
j
];
j
++;
}
k
++;
}
// Left Part
while
(
i
<=
mid
) {
temp
[
k
++] =
arr
[
i
++];
}
// Right Patr
while
(
j
<=
ei
) {
temp
[
k
++] =
arr
[
j
++];
}
// Copy temp to orginal
for
(
k
=
0
,
i
=
si
;
k
<
temp
.
length
;
k
++,
i
++) {
arr
[
i
] =
temp
[
k
];
}
}
public
static
void
main
(
String
[]
args
) {
int
arr
[] = {
6
,
3
,
9
,
5
,
2
,
8
};
margeSort
(
arr
,
0
,
arr
.
length
-
1
);
PrintArray
(
arr
);
}
}
Back
|
FazBrowse Home
|
New Git URL