Update Dijkstra.java
This commit is contained in:
parent
c9d0aa1290
commit
66c6353705
@ -63,13 +63,11 @@ class Graph {
|
|||||||
public Vertex previous = null;
|
public Vertex previous = null;
|
||||||
public final Map<Vertex, Integer> neighbours = new HashMap<>();
|
public final Map<Vertex, Integer> neighbours = new HashMap<>();
|
||||||
|
|
||||||
public Vertex(String name)
|
public Vertex(String name){
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printPath()
|
private void printPath(){
|
||||||
{
|
|
||||||
if (this == this.previous)
|
if (this == this.previous)
|
||||||
{
|
{
|
||||||
System.out.printf("%s", this.name);
|
System.out.printf("%s", this.name);
|
||||||
@ -85,16 +83,14 @@ class Graph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Vertex other)
|
public int compareTo(Vertex other){
|
||||||
{
|
|
||||||
if (dist == other.dist)
|
if (dist == other.dist)
|
||||||
return name.compareTo(other.name);
|
return name.compareTo(other.name);
|
||||||
|
|
||||||
return Integer.compare(dist, other.dist);
|
return Integer.compare(dist, other.dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString()
|
@Override public String toString(){
|
||||||
{
|
|
||||||
return "(" + name + ", " + dist + ")";
|
return "(" + name + ", " + dist + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,4 +171,4 @@ class Graph {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user