Skip to content

Commit 49d44bc

Browse files
committed
feat: 가중치 그래프 간선 추가 기능 구현
1 parent 413b3e5 commit 49d44bc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

yoonexample/src/main/java/graph/ListWeightGraph.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public ListWeightGraph(int vertexCount, Class<? extends Enum<?>> clazz) {
2525

2626
@Override
2727
public void addEdge(Enum<?> fromV, Enum<?> toV, int weight) {
28+
WeightEdge edge = new WeightEdge(weight, fromV, toV);
29+
vertices[fromV.ordinal()].insert(toV);
30+
vertices[toV.ordinal()].insert(fromV);
2831

32+
edgePriorityQueue.enqueue(edge);
2933
}
3034

3135
@Override
@@ -60,8 +64,14 @@ public String breadthFirstSearch(Enum<?> startV) {
6064

6165
private static class WeightEdge {
6266

63-
private int weight;
64-
private Enum<?> fromVertex;
65-
private Enum<?> toVertex;
67+
private final int weight;
68+
private final Enum<?> fromVertex;
69+
private final Enum<?> toVertex;
70+
71+
public WeightEdge(int weight, Enum<?> fromVertex, Enum<?> toVertex) {
72+
this.weight = weight;
73+
this.fromVertex = fromVertex;
74+
this.toVertex = toVertex;
75+
}
6676
}
6777
}

0 commit comments

Comments
 (0)