This week's book giveaway is in the JavaScript forum. We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line! See this thread for details.

I'm implementing Dijkstra's algorithm in Java. I need help in creating an arraylist of stacks that will be used to store the predecessors table, which means that for every element's shortest path, the predecessors taken to get there would be in the stack.

Here's the code I have

I'm unable to add the the stack to prev arraylist. The error is

The method add(E) in the type ArrayList<E> is not applicable for the arguments (predec<E>)

.

I have implemented a TreeMap, with the mainNodes arraylist storing all the elements in the map.