Implementing Dijkstra's search

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 ...

Get Hands-On Artificial Intelligence with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.