FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-DSA/QueueChapter.java at main · shanks-d-fury/Java-DSA · GitHub
shanks-d-fury
/
Java-DSA
Public
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-DSA
/
QueueChapter.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (29 loc) · 834 Bytes
Breadcrumbs
Java-DSA
/
QueueChapter.java
Copy path
File metadata and controls
32 lines (29 loc) · 834 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
27
28
29
30
31
32
import
java
.
util
.
LinkedList
;
import
java
.
util
.
Queue
;
public
class
QueueChapter
{
public
static
Queue
<
Integer
>
interLeave_2_halves
(
Queue
<
Integer
>
q
) {
int
i
=
0
;
int
size
=
q
.
size
();
Queue
<
Integer
>
q1
=
new
LinkedList
<>();
while
(
i
<
size
/
2
) {
q1
.
add
(
q
.
remove
());
i
++;
}
while
(!
q1
.
isEmpty
()) {
q
.
add
(
q1
.
remove
());
q
.
add
(
q
.
remove
());
}
return
q
;
}
public
static
void
main
(
String
args
[]) {
int
input
[] = {
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
Queue
<
Integer
>
qx
=
new
LinkedList
<>();
for
(
int
x
:
input
) {
qx
.
add
(
x
);
}
Queue
<
Integer
>
q
=
interLeave_2_halves
(
qx
);
while
(!
q
.
isEmpty
()) {
System
.
out
.
print
(
q
.
remove
() +
" "
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL