Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • That's meant to be the length of the list of nodes. It should always be the same for your situation (5 for the example you gave). Commented Oct 21, 2010 at 23:15
  • I'm working on a switch statement for the distance function and I don't want to type the same distances with source and destination reversed. Is there something else I can do? Commented Oct 21, 2010 at 23:24
  • 1
    Don't use a switch statement. Put the distances in a matrix (type vector<vector<int> >). Then you can just return distances[i][i+1]. The subscripts should be the node values. So for nodes a and b, you might do distances[0][1]. Furthermore, you can first put the two parameters in increasing order, so given b, a, you'd switch them to a, b. Commented Oct 21, 2010 at 23:27