Update Dijkstra.java

This commit is contained in:
rmakynen 2018-10-09 09:05:59 +03:00 committed by GitHub
parent c9d0aa1290
commit 66c6353705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
} }
} }
} }