These include test programs that can be directly compiled
Compiled in Windows XP Professional, DEV-CPP V4.9.9.0
Refer to the computer network (third edition)
/ ************************************** Name: Dijkstra Routing Algorithm Example ** Program: FINYTANG ** Date: 2005.4.10 ** Version: 1.0 *********************************************** /
#include
#define infinity 10000000 / * is not arrogant * / # define max_nodes 8 / * maximum number of nodes * /
Struct State / * Node Structure Variable * / {INT Predecessor; Int Length; Enum {Permanent = 0, Tentative} Label;} State [MAX_NODES];
INT n = max_nodes;
/ * Node configuration diagram, 0 means not adjacent * / int Dist [max_nodes] = {0, 2, 0, 0, 0, 0, 0}, {2, 0, 7, 0, 2, 0, 7, 0, 3, 0, 3, 0, 0}, {0, 0, 3, 0, 0, 0, 0, 8}, {0, 2, 0, 0, 0, 2, 1, 0}, {0, 0, 3, 0, 2, 0, 0, 2}, {6, 0, 0, 0, 1, 0, 0, 8}, { 0, 0, 0, 2, 0, 2, 4, 0}};
Void dijkstra_ra (int S, int T, int path []); / * core algorithm function, S end node, Path shortest path * / void outputdata (); / * Output function * /
INT Main (int Argc, char * argv []) {int path [max_nodes]; INT i; int S, t; for (i = 0; i
Void dijkstra_ra (int S, int T, int path []) {INT I, K, Min; Struct State * p; for (p = state; p