How do I set up a 2d vector
I am writing a program to do Dijkstra''s shortest path algorithm and I am trying to create a 2d weight vector, since I don''t know the upper limits of the number of nodes. How would I set one up that would hold the distance between the two nodes?
Could you please reformulate your text? I can''t figure out what you mean.
Thanks, Arthur(rockslave)
Thanks, Arthur(rockslave)
import money.*;#include "cas.h"uses bucks;
Dijskstra''s Algorithm for shortest paths has a 2d array which it uses to formulate the shortest path from the given source to every other node in the graph. It looks something like this:
__0_1_2_3_
0|0 1 9 0
1|1 0 2 4
2|5 2 0 0
3|0 0 1 0
the array has the node number (0, 1, 2, ..) across the side and all of its adjacent nodes and their distances in the rows. So for example, the distance from node 0 to node 2 is 9.
Now I just can''t figure out a nice way to do a vector of vectors to accomplish the 2d array.
i was thinking something along these lines:
vector< vector > Weights;
I was just curious if anyone could think of an easier dynamic implementation, without a performance drop. Linked lists aren''t really an option cause I''d really rather not mess with writing anymore code than I have to.
__0_1_2_3_
0|0 1 9 0
1|1 0 2 4
2|5 2 0 0
3|0 0 1 0
the array has the node number (0, 1, 2, ..) across the side and all of its adjacent nodes and their distances in the rows. So for example, the distance from node 0 to node 2 is 9.
Now I just can''t figure out a nice way to do a vector of vectors to accomplish the 2d array.
i was thinking something along these lines:
vector< vector > Weights;
I was just curious if anyone could think of an easier dynamic implementation, without a performance drop. Linked lists aren''t really an option cause I''d really rather not mess with writing anymore code than I have to.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement