Now, we will look at the code for Dijkstra's search algorithm, which we discussed in the An introduction to searching section.
Let's get straight to the code, and look at how it works. In the previous section, the very first thing that we showed were the vertices; each vertex had certain properties. We will now create a Vertex class, as follows:
public class Vertex {
final private String id;
final private String name;
public Vertex(String id, String name) {
this.id = id;
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
...