FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code/Algorithm/parition.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
/
parition.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
84 lines (61 loc) · 1.48 KB
Breadcrumbs
code
/
Algorithm
/
parition.java
Copy path
File metadata and controls
executable file
·
84 lines (61 loc) · 1.48 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package
partition
;
import
java
.
util
.
Scanner
;
public
class
parition
{
public
void
part
(
int
[]
array
,
int
max_partition
,
int
[]
partition_blocks
)
{
int
n
=
0
;
int
v
=
0
;
for
(
int
i
=
0
;
i
<
max_partition
;
i
++)
{
int
temp_array
[]=
new
int
[
partition_blocks
[
i
]];
/*if(i==max_partition-1){
n=n-1;
}
else
{*/
for
(
int
j
=
n
;
j
<
n
+
partition_blocks
[
i
];
j
++)
{
temp_array
[
j
-
n
]=
array
[
j
];
}
v
=
v
+
IntraBlockDist
(
temp_array
);
// }
n
=
n
+
partition_blocks
[
i
];
}
System
.
out
.
println
(
"Intra Block for this partition: "
+
v
);
}
public
int
IntraBlockDist
(
int
[]
temp_array
){
if
(
temp_array
.
length
==
1
)
return
0
;
else
{
int
calc
=
0
;
for
(
int
i
=
0
;
i
<
temp_array
.
length
-
1
;
i
++)
{
for
(
int
j
=
i
+
1
;
j
<
temp_array
.
length
;
j
++ )
{
calc
=
calc
+
distance
(
temp_array
[
i
],
temp_array
[
j
]);
}
}
return
calc
;
}}
public
int
distance
(
int
i
,
int
j
)
{
int
l
=
0
;
l
=
Math
.
abs
(
i
-
j
);
return
l
;
}
public
static
void
main
(
String
[]
args
) {
Scanner
in
=
new
Scanner
(
System
.
in
);
int
[]
array
=
new
int
[
5
];
int
[]
partition_blocks
=
new
int
[
3
];
System
.
out
.
print
(
"Enter data elements :"
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
array
[
i
]=
in
.
nextInt
();
int
max_partition
=
3
;
System
.
out
.
print
(
"Enter partition format :"
);
for
(
int
i
=
0
;
i
<
3
;
i
++)
partition_blocks
[
i
]=
in
.
nextInt
();
parition
p
=
new
parition
();
p
.
part
(
array
,
max_partition
,
partition_blocks
);
}
}
Back
|
FazBrowse Home
|
New Git URL