-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDfs.java
More file actions
38 lines (32 loc) · 927 Bytes
/
Dfs.java
File metadata and controls
38 lines (32 loc) · 927 Bytes
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
package test;
public class Dfs extends CommonSearcher {
int time=0;
@Override
public boolean search(Searchable s) {
for(State vertex: s.getGraph()) {
if(vertex.color==1) {
dfsVisit(vertex);
}
}
return true;
}
private void dfsVisit(State u) {
u.setColor(2);
this.time= this.time+1;
u.setDistance(this.time);
for (State ver: u.getNieboresList()) {
if(ver.getColor()==1) {
ver.setFather(u);
dfsVisit(ver);
}
}
u.setColor(3);
time=time+1;
u.setEndtime(this.time);
if(u.getFather() !=null) {
System.out.println("vertex "+u.name+ " startime is: "+ u.getDistance() + " end time is: "+ u.getEndtime() +" The father is :" + u.getFather().name);
}else {
System.out.println("vertex "+u.name+ " startime is: "+ u.getDistance() + " end time is: "+ u.getEndtime() +" The father is null");
}
}
}