| | |
dijkstra algorithm problem in c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Here is some pseudocode code
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Nov 2007
Posts: 10
Reputation:
Solved Threads: 1
shortestPath(in theGraph, in weight:WeightArray) {
// Finds the minimum-cost paths between an origin vertex (vertex 0)
// and all other vertices in a weighted directed graph theGraph;
// theGraph’s weights are nonnegative
Create a set vertexSet that contains only vertex 0;
n = number of vertices in the Graph;
// Step 1
for (v=0 through n-1)
weight[v] = matrix[0][v];
// Steps 2 through n
for (step=2 through n) {
Find the smallest weight[v] such that v is not in vertexSet;
Add v to vertexSet;
for (all vertices u not in vertexSet)
if (weight[u] > weight[v]+matrix[v][u])
weigth[u] = weight[v]+matrix[v][u];
}
}
Algorithm is above if u try to find this algorithm but i think nobody develops a code for u here. Because it seems like it's your homework. right?
// Finds the minimum-cost paths between an origin vertex (vertex 0)
// and all other vertices in a weighted directed graph theGraph;
// theGraph’s weights are nonnegative
Create a set vertexSet that contains only vertex 0;
n = number of vertices in the Graph;
// Step 1
for (v=0 through n-1)
weight[v] = matrix[0][v];
// Steps 2 through n
for (step=2 through n) {
Find the smallest weight[v] such that v is not in vertexSet;
Add v to vertexSet;
for (all vertices u not in vertexSet)
if (weight[u] > weight[v]+matrix[v][u])
weigth[u] = weight[v]+matrix[v][u];
}
}
Algorithm is above if u try to find this algorithm but i think nobody develops a code for u here. Because it seems like it's your homework. right?
![]() |
Similar Threads
- Dijkstra Algorithm (Computer Science)
- algorithm problem with recursion (Java)
- Dijkstra algorithm (Networking Hardware Configuration)
- Algorithm problem (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Pointer Conversion Problem
- Next Thread: Problem with searching and Edit
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






