FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/other/dfs.java at master · javaarchive/Java · GitHub
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
javaarchive
/
Java
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
3
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
other
/
dfs.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (50 loc) · 1.15 KB
Breadcrumbs
Java
/
other
/
dfs.java
Copy path
File metadata and controls
51 lines (50 loc) · 1.15 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
import
java
.
util
.*;
public
class
dfs
implements
VisitListener
{
public
void
onVisit
(
node
n
) {
// Do nothing
System
.
out
.
println
(
n
.
getId
());
}
public
Stack
<
node
>
q
=
new
Stack
<
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
.
pop
();
if
(
cur
.
isvisited
()) {
continue
;
}
cur
.
visit
();
search
.
onVisit
(
cur
);
Collections
.
reverse
(
cur
.
connectedNodes
);
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
dfs
()).
search
(
a
);
}
}
Back
|
FazBrowse Home
|
New Git URL