FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/java-combinations/src/main/java/com/hmkcode/Shifting.java at master · dkaba/Java · GitHub
dkaba
Java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
java-combinations
/
src
/
main
/
java
/
com
/
hmkcode
/
Shifting.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (54 loc) · 1.45 KB
Breadcrumbs
Java
/
java-combinations
/
src
/
main
/
java
/
com
/
hmkcode
/
Shifting.java
Copy path
File metadata and controls
66 lines (54 loc) · 1.45 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
package
com
.
hmkcode
;
public
class
Shifting
{
public
static
void
main
(
String
[]
args
)
{
String
[]
e
= {
"A"
,
"B"
,
"C"
,
"D"
,
"E"
};
int
k
=
3
;
combination
(
e
,
k
);
}
public
static
void
combination
(
Object
[]
e
,
int
k
){
int
[]
ignore
=
new
int
[
e
.
length
-
k
];
// --> [0][0]
int
[]
combination
=
new
int
[
k
];
// --> [][][]
// set initial ignored elements
//(last k elements will be ignored)
for
(
int
w
=
0
;
w
<
ignore
.
length
;
w
++)
ignore
[
w
] =
e
.
length
-
k
+(
w
+
1
);
int
i
=
0
,
r
=
0
,
g
=
0
;
boolean
terminate
=
false
;
while
(!
terminate
){
// selecting N-k non-ignored elements
while
(
i
<
e
.
length
&&
r
<
k
){
if
(
i
!=
ignore
[
g
]){
combination
[
r
] =
i
;
r
++;
i
++;
}
else
{
if
(
g
!=
ignore
.
length
-
1
)
g
++;
i
++;
}
}
print
(
combination
,
e
);
i
=
0
;
r
=
0
;
g
=
0
;
terminate
=
true
;
// shifting ignored indices
for
(
int
w
=
0
;
w
<
ignore
.
length
;
w
++){
if
(
ignore
[
w
] >
w
){
ignore
[
w
]--;
if
(
w
>
0
)
ignore
[
w
-
1
] =
ignore
[
w
]-
1
;
terminate
=
false
;
break
;
}
}
}
}
private
static
void
print
(
int
[]
combination
,
Object
[]
elements
){
String
output
=
""
;
for
(
int
z
=
0
;
z
<
combination
.
length
;
z
++){
output
+=
elements
[
combination
[
z
]];
}
System
.
out
.
println
(
output
);
}
}
Back
|
FazBrowse Home
|
New Git URL