-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
46 lines (34 loc) · 1003 Bytes
/
Copy pathMain.java
File metadata and controls
46 lines (34 loc) · 1003 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
39
40
41
42
43
44
45
46
package BFS;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class Main {
public static void main(String[] args) {
}
static List<List<Integer>> list;//정점 인접리스트
static int N;//정점 리스트 갯수
public void BFS(Integer start){
Queue<Integer> queue = new LinkedList<>();
queue.add(start);
boolean[] visited = new boolean[N];
visited[start] = true;
while(!queue.isEmpty()){
Integer currentPoint = queue.poll();
for(int i=0; i<list.get(currentPoint).size(); i++){
Integer nextPoint = currentPoint + list.get(currentPoint).get(i);
if(!visited[nextPoint]){
queue.offer(nextPoint);
visited[nextPoint] = true;
}
}
}
}
}
class Point{
int x;
Point nextPoint;
public Point(int x){
this.x = x;
this.nextPoint = null;
}
}