title: Implementing Dijkstra's Algorithm
body: <p>I've been tasked (coursework @ university) to implement a form of path-finding. Now, in-spec, I could just implement a brute force, since there's a limit on the number of nodes to search (begin, two in the middle, end), but I want to re-use this code and came to implement <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow noreferrer">Dijkstra's algorithm</a>.</p>
  
  <p>I've seen the pseudo on Wikipedia and a friend wrote some for me as well, but it flat out doesn't make sense. The algorithm seems pretty simple and it's not a problem for me to understand it, but I just can't for the life of me visualize the code that would realize such a thing.</p>
  
  <p>Any suggestions/tips?</p>
  
  <p>Edit for some confusions:<br>
  Yes, there is a target node and a source node. <br>
  I'm looking to implement Dijkstra's in a general case, not the "only two intermediate stops" case, because  I want to use the code again afterwards. Else, I'd just write a brute-force implementation.<br>
  The specific issue that I'm having a little trouble with is storing the sub-optimal half-formed paths, in case they may become optimal. When I'm visiting a given node, I just don't see how I'm going to update all the connections that go through it.<br>
  More edit:<br>
  Going through a couple of the answers now and having a go.<br></p>
  
  <p>REALLY EDIT:
  I forgot to mention a serious complication, which is that any two vertices can have up to UINT_MAX different distances between them. Sorry. Infact, the fact that I forgot to deal with this is probably the cause of the damn problem in the first place, although the solution: pick the shortest is fortunately obvious to me. No wonder other people's pseudo for a distance variable didn't take into account my variable distance.</p>