Hello, I've code below, (yes, it's graph implementation, no queue/depth first/etc.)
--> How to ease loop operations? (less = good)
Code:
// pre-condition
/*
struct graph {
bool v; // visited
int d; // distance
int p; // path
};
int cost[size][size];
int size;
graph G[size][size];
*/
void dijkstra::find() {
int target = 0;
for (int ptA = 1; ptA <= size; ptA++) {
for (int i = 1; i <= size; i++) {
int low = 2147483647; // infinity
for (int v = 1; v <= size; v++) {
if (!G[ptA][v].v && G[ptA][v].d < low) {
target = v;
low = G[ptA][v].d;
}
}
G[ptA][target].v = true;
for (int w = 1; w <= size; w++) {
if (!G[ptA][w].v && cost[target][w] != 2147483647) {
int curr = 0;
curr += G[ptA][target].d;
curr += cost[target][w];
if (G[ptA][w].d > curr) {
G[ptA][w].d = G[ptA][target].d + cost[target][w];
G[ptA][w].p = target;
}
}
}
}
}
}
Cheers,
Lj