Updated code comments to portuguese (#20785)
* Updated code comments to portuguese * Fixado erros de sintaxe
This commit is contained in:
committed by
Jefferson Oliveira
parent
92e87f9b7e
commit
4d5677a66e
@ -17,13 +17,13 @@ import java.util.*;
|
|||||||
public class Dijkstra {
|
public class Dijkstra {
|
||||||
class Graph {
|
class Graph {
|
||||||
LinkedList<Pair<Integer>> adj[];
|
LinkedList<Pair<Integer>> adj[];
|
||||||
int n; // Number of vertices.
|
int n; // Numero de vértices
|
||||||
Graph(int n) {
|
Graph(int n) {
|
||||||
this.n = n;
|
this.n = n;
|
||||||
adj = new LinkedList[n];
|
adj = new LinkedList[n];
|
||||||
for(int i = 0;i<n;i++) adj[i] = new LinkedList<>();
|
for(int i = 0;i<n;i++) adj[i] = new LinkedList<>();
|
||||||
}
|
}
|
||||||
// add a directed edge between vertices a and b with cost as weight
|
// Adiciona um vértices dirigido entre a e b com custo igual ao peso
|
||||||
public void addEdgeDirected(int a, int b, int cost) {
|
public void addEdgeDirected(int a, int b, int cost) {
|
||||||
adj[a].add(new Pair(b, cost));
|
adj[a].add(new Pair(b, cost));
|
||||||
}
|
}
|
||||||
@ -48,9 +48,9 @@ import java.util.*;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculates shortest path to each vertex from source and returns the distance
|
// Calcula o caminho mais curto para cada vértice apartir da fonte e retorna a distância
|
||||||
public int[] dijkstra(Graph g, int src) {
|
public int[] dijkstra(Graph g, int src) {
|
||||||
int distance[] = new int[gn]; // shortest distance of each vertex from src
|
int distance[] = new int[gn]; // Menor distância de cada vértice da fonte
|
||||||
boolean visited[] = new boolean[gn]; // vertex is visited or not
|
boolean visited[] = new boolean[gn]; // vertex is visited or not
|
||||||
Arrays.fill(distance, Integer.MAX_VALUE);
|
Arrays.fill(distance, Integer.MAX_VALUE);
|
||||||
Arrays.fill(visited, false);
|
Arrays.fill(visited, false);
|
||||||
@ -58,17 +58,17 @@ import java.util.*;
|
|||||||
pq.add(new Pair<Integer>(src, 0));
|
pq.add(new Pair<Integer>(src, 0));
|
||||||
distance[src] = 0;
|
distance[src] = 0;
|
||||||
while(!pq.isEmpty()) {
|
while(!pq.isEmpty()) {
|
||||||
Pair<Integer> x = pq.remove(); // Extract vertex with shortest distance from src
|
Pair<Integer> x = pq.remove(); // Retira o vértice com menor distância à fonte
|
||||||
int u = x.first;
|
int u = x.first;
|
||||||
visited[u] = true;
|
visited[u] = true;
|
||||||
Iterator<Pair<Integer>> iter = g.adj[u].listIterator();
|
Iterator<Pair<Integer>> iter = g.adj[u].listIterator();
|
||||||
// Iterate over neighbours of u and update their distances
|
// Itera sobre os visinhos de u e atualiza as suas distâncias
|
||||||
while(iter.hasNext()) {
|
while(iter.hasNext()) {
|
||||||
Pair<Integer> y = iter.next();
|
Pair<Integer> y = iter.next();
|
||||||
int v = y.first;
|
int v = y.first;
|
||||||
int weight = y.second;
|
int weight = y.second;
|
||||||
// Check if vertex v is not visited
|
// Verifica se vértice v não foi visitado
|
||||||
// If new path through u offers less cost then update distance array and add to pq
|
// Se o novo caminho u oferece menor custo, actualiza o vetor de distâncias e adiciona a pq
|
||||||
if(!visited[v] && distance[u]+weight<distance[v]) {
|
if(!visited[v] && distance[u]+weight<distance[v]) {
|
||||||
distance[v] = distance[u]+weight;
|
distance[v] = distance[u]+weight;
|
||||||
pq.add(new Pair(v, distance[v]));
|
pq.add(new Pair(v, distance[v]));
|
||||||
@ -92,4 +92,4 @@ import java.util.*;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user