MCPcopy Create free account
hub / github.com/Seogeurim/CS-study / getShortestDistance

Method getShortestDistance

contents/algorithm/code/DijkstraTest.java:64–88  ·  view source on GitHub ↗
(int S)

Source from the content-addressed store, hash-verified

62 }
63
64 public void getShortestDistance(int S) {
65 /* init */
66 for (int i = 1; i <= N; i++) {
67 if (i != S) D[i] = INF;
68 }
69
70 /* 출발 정점 초기화 */
71 visited[S] = true;
72 for (int i = 1; i <= N; i++) {
73 if (i != S && graph[S][i] > 0) D[i] = graph[S][i];
74 }
75
76 /* dijkstra */
77 for (int i = 0; i < N-1; i++) {
78 int current = getNextNode();
79 visited[current] = true;
80 for (int j = 1; j <= N; j++) {
81 if (graph[current][j] > 0) {
82 D[j] = Math.min(D[j], D[current] + graph[current][j]);
83 }
84 }
85 }
86
87 printDistance();
88 }
89
90 private int getNextNode() {
91 int min_value = INF;

Callers 1

mainMethod · 0.95

Calls 2

getNextNodeMethod · 0.95
printDistanceMethod · 0.95

Tested by

no test coverage detected