Skip to content

Commit 66774dc

Browse files
authored
Changed to only English comments
1 parent 8b9ca96 commit 66774dc

File tree

1 file changed

+18
-49
lines changed

1 file changed

+18
-49
lines changed

src/java/Dijkstra.java

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
// Algoritimo de Dijkstra (Dijkstra's Algorithm)
1+
// Dijkstra's Algorithm
22
// Anderson Carneiro da Silva
33
// https://github.com/AndersonSheep
44

5-
// Baseado no método do GeekforGeeks
6-
// Um programa Java para o algoritmo de caminho mais curto de fonte única de Dijkstra.
7-
// O programa é para representação da matriz de adjacência do grafo
8-
9-
/* Based on the GeekforGeeks method
10-
A Java program for Dijkstra's single-source shortest path algorithm.
11-
The program is for the representation of the graph's adjacency matrix */
12-
5+
// Based on the GeekforGeeks method
6+
// A Java program for Dijkstra's single-source shortest path algorithm.
7+
// The program is for the representation of the graph's adjacency matrix.
138
import java.io.*;
149
import java.util.*;
1510

1611
class ShortestPath {
17-
// Uma função de utilidade para encontrar o vértice com valor mínimo de distância,
18-
// do conjunto de vértices ainda não incluídos na árvore do caminho mais curto
19-
20-
/* A utility function to find the vertex with the minimum distance value,
21-
from the set of vertices not yet included in the shortest path tree */
12+
// A utility function to find the vertex with the minimum distance value,
13+
// from the set of vertices not yet included in the shortest path tree
2214
static final int V = 9;
2315

2416
int minDistance(int dist[], Boolean sptSet[]) {
25-
// Iniciando um valor minimo
26-
// Initializing a minimum value
17+
// Initialize a minimum value
2718
int min = Integer.MAX_VALUE, min_index = -1;
2819

2920
for (int v = 0; v < V; v++) {
@@ -36,7 +27,6 @@ int minDistance(int dist[], Boolean sptSet[]) {
3627
return min_index;
3728
}
3829

39-
// Uma função de utilidade para imprimir a matriz de distância construída
4030
// A utility function to print the constructed distance matrix
4131
void printSolution(int dist[]) {
4232
System.out.println("Vertex \t\t Distance from Source");
@@ -45,59 +35,40 @@ void printSolution(int dist[]) {
4535
}
4636
}
4737

48-
// Função que implementa o caminho mais curto da fonte única de Dijkstra
49-
// algoritmo para um grafo representado usando matriz de adjacência
50-
51-
/* Function that implements Dijkstra's single-source shortest path algorithm
52-
for a graph represented using an adjacency matrix */
38+
// Function that implements Dijkstra's single-source shortest path algorithm
39+
// for a graph represented using an adjacency matrix
5340
void dijkstra(int graph[][], int src) {
54-
// A matriz de saída. dist [i] irá manter a menor distância de src a i
5541
// The output array. dist[i] will hold the shortest distance from src to i
5642
int dist[] = new int[V];
5743

58-
// sptSet [i] será verdadeiro se o vértice i for incluído no mais curto
59-
// árvore do caminho ou distância mais curta de src para i é finalizada
60-
61-
/* sptSet[i] will be true if vertex i is included in the shortest
62-
path tree or the shortest distance from src to i is finalized */
44+
// sptSet[i] will be true if vertex i is included in the shortest
45+
// path tree or the shortest distance from src to i is finalized
6346
Boolean sptSet[] = new Boolean[V];
6447

65-
// Inicializa todas as distâncias como INFINITE e stpSet [] como falso
6648
// Initialize all distances as INFINITE and sptSet[] as false
6749
for (int i = 0; i < V; i++) {
6850
dist[i] = Integer.MAX_VALUE;
6951
sptSet[i] = false;
7052
}
7153

72-
// A distância do vértice de origem é sempre 0
7354
// The distance of the source vertex is always 0
7455
dist[src] = 0;
7556

76-
// Encontre o caminho mais curto para todos os vértices
7757
// Find the shortest path for all vertices
7858
for (int count = 0; count < V - 1; count++) {
79-
// Escolha o vértice de distância mínima do conjunto de vértices
80-
// ainda não processado. vc é sempre igual a src na primeira iteração.
81-
82-
/* Pick the vertex with the minimum distance from the set of vertices
83-
not yet processed. u is always equal to src in the first iteration. */
59+
// Pick the vertex with the minimum distance from the set of vertices
60+
// not yet processed. u is always equal to src in the first iteration.
8461
int u = minDistance(dist, sptSet);
8562

86-
// Marque o vértice escolhido como processado
8763
// Mark the chosen vertex as processed
8864
sptSet[u] = true;
8965

90-
// Atualize o valor dist dos vértices adjacentes do vértice escolhido.
91-
// Update the value dist for the adjacent vertices of the chosen vertex.
66+
// Update the value of dist for the adjacent vertices of the chosen vertex
9267
for (int v = 0; v < V; v++)
9368

94-
// Atualize dist [v] apenas se não estiver em sptSet, há um
95-
// borda de u a v, e peso total do caminho de src a
96-
// v a u é menor que o valor atual de dist [v]
97-
98-
/* Update dist[v] only if it's not in sptSet, there is an edge from u to v,
99-
and the total weight of the path from src to v through u is less than the
100-
current value of dist[v] */
69+
// Update dist[v] only if it's not in sptSet, there is an edge from u to v,
70+
// and the total weight of the path from src to v through u is less than the
71+
// current value of dist[v]
10172
if (!sptSet[v]
10273
&& graph[u][v] != 0
10374
&& dist[u] != Integer.MAX_VALUE
@@ -106,14 +77,12 @@ void dijkstra(int graph[][], int src) {
10677
}
10778
}
10879

109-
// Imprime a matriz de distância construída
11080
// Print the constructed distance matrix
11181
printSolution(dist);
11282
}
11383

11484
public static void main(String[] args) {
115-
// Vamos criar o gráfico de exemplo discutido acima
116-
//Let's create the example graph discussed above
85+
// Let's create the example graph discussed above
11786
int graph[][] =
11887
new int[][] {
11988
{0, 4, 0, 0, 0, 0, 0, 8, 0},

0 commit comments

Comments
 (0)