-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.java
44 lines (37 loc) · 994 Bytes
/
Vertex.java
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
import java.util.LinkedList;
public class Vertex{
public int index;
public Vertex predecessor;
public int currentCost;
public boolean visited;
public LinkedList<Vertex> neighbors;
public Vertex(){
this.predecessor = this;
this.currentCost = 0;
this.neighbors = new LinkedList<Vertex>();
}
public Vertex(int id, int chave){
this.index = id;
this.currentCost = chave;
}
public Vertex[] getNeighbors(){
Vertex[] neighbors = new Vertex[this.neighbors.size()];
for( int i = 0; i < this.neighbors.size(); i++ ){
neighbors[i] = this.neighbors.get(i);
}
return neighbors;
}
public Vertex getNeighbor(int i){
return this.neighbors.get(i);
}
public Vertex GetMinimumNeighbor(){
Vertex vertexMin = null;
if(this.neighbors.size() > 0)
vertexMin = this.neighbors.get(0);
for(int i = 0; i < this.neighbors.size(); i++){
if(this.getNeighbor(i).currentCost < vertexMin.currentCost)
vertexMin = this.getNeighbor(i);
}
return vertexMin;
}
}