FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-tools/other/bfs.java at master · javaarchive/java-tools · GitHub
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
javaarchive
/
java-tools
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-tools
/
other
/
bfs.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (49 loc) · 1.1 KB
Breadcrumbs
java-tools
/
other
/
bfs.java
Copy path
File metadata and controls
50 lines (49 loc) · 1.1 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
import
java
.
util
.*;
public
class
bfs
implements
VisitListener
{
public
void
onVisit
(
node
n
) {
// Do nothing
System
.
out
.
println
(
n
);
}
public
Queue
<
node
>
q
=
new
LinkedList
<
node
>();
public
ArrayList
<
node
>
vn
=
new
ArrayList
<
node
>();
public
ArrayList
<
node
>
search
(
node
startNode
,
VisitListener
search
) {
this
.
q
.
clear
();
this
.
vn
.
clear
();
this
.
q
.
add
(
startNode
);
this
.
vn
.
add
(
startNode
);
node
cur
;
while
(!(
q
.
isEmpty
())) {
cur
=
this
.
q
.
poll
();
if
(
cur
.
isvisited
()) {
continue
;
}
cur
.
visit
();
search
.
onVisit
(
cur
);
for
(
node
sub
:
cur
.
connectedNodes
) {
q
.
add
(
sub
);
vn
.
add
(
sub
);
}
}
return
vn
;
}
public
ArrayList
<
node
>
search
(
node
startNode
) {
return
this
.
search
(
startNode
,
this
);
}
public
static
void
main
(
String
[]
args
) {
node
a
,
b
,
c
,
d
,
e
,
f
,
g
;
a
= (
new
node
()).
setid
(
1
);
b
= (
new
node
()).
setid
(
2
);
c
= (
new
node
()).
setid
(
3
);
a
.
linkNode
(
b
);
a
.
linkNode
(
c
);
d
= (
new
node
()).
setid
(
4
);
e
= (
new
node
()).
setid
(
5
);
f
= (
new
node
()).
setid
(
6
);
g
= (
new
node
()).
setid
(
7
);
b
.
linkNode
(
d
);
b
.
linkNode
(
e
);
c
.
linkNode
(
f
);
c
.
linkNode
(
g
);
(
new
bfs
()).
search
(
a
);
}
}
Back
|
FazBrowse Home
|
New Git URL