I have an exercise on Dijkstra's Algorithm and when I run my programm I get the following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 48
What is wrong? I can't sent the entire code because it is 200 lines. But the problem appears in those lines in cmd
dist[i] = Integer.MAX_VALUE; and
dist[i] = 0;
Thanks in advnace for your help.
public static void DijkstraOnNode (int start) {
int[] dist = new int [myNodes.size()]; //where myNodes is an ArrayList of Hashset<Link>
//and Link is a class that contains node kai weight
int[] pred = new int [myNodes.size()];
int[] pq = new int [myNodes.size()];
for (int i = 0; i <= myNodes.size(); i++) {
if (i!= start)
dist[i] = Integer.MAX_VALUE;
else
dist[i] = 0;
pq[i] = dist[i];
}
(the code continues)