C source code for distance vector routing algorithm

xiaoxiao2021-03-06  60

I haven't been here for a long time. After learning the model, I tried to plan a graphics processing software. I have learned the model and have not learned it. I have a lot of ability to grasp the ability of the software overall situation. These two weeks have also taken the computer graphics program. In the first two days, I have introduced Direct3D. I didn't know what the API didn't know how DirectDraw. I only remember that DirectDraw was so hard. It is now just that Direct3D has not been feeling at that time, just the knowledge of matrix transformation is a big semester, now I have forgotten, I don't know how to plan a plane normal. Last night, I wrote a procedure, and I was wrong from the vector routing algorithm. I thought it was a dynamic planning issue until I saw it when I wrote it yesterday. I haven't paid an article for a long time, and I will be a bit of something to write here today. /*Routine.c TC2.0 WinXP * / # include #include #include #define Routnum 7

Typedef struct {int 4; tentNode;

Routnode Data [ROUTNUM] [ROUTNUM]; / * Routing table * /

Void initdata (file * pfile); / * read data from the data file, initialize the routing table * / void outputdata (); / * Output All Route Table * / Void Communication (int RECV, INT Send); / * Send Point Send your own routing table * / void exchange (); / * All nodes for a data exchange, update the routing table * /

Void main () {int Start, end; int i; file * pfile; pfile = fopen ("data.txt", "r"); if (pfile == null) {printf ("Data file failed to open, Press Any key to quit./N "); getch (); return;} else initdata; fclose (pfile); Printf (" / ninitial state: / n "); OUTPUTROTDATA (); for (i = 0; I

Printf ("INPUT The Start Node (% D-% D):", 0, RoutNum-1); Scanf ("% D", & Start); Printf ("INPUT The end Node (% D-% d):" , 0, ROUTNUM-1; scanf ("% D", & end); if (start == end || Start <0 || START> 6 || End <0 || end> ​​6) {printf ("/ NWrong Input, Press any key to quit./N "); getCH (); return;} else {int cur = start; int total = 0; if (data [start] [end] .dis <0) {printf "NO ROUTINE FIND! / N"); getCH (); return;} printf ("% c->", CUR 65); while (data [cur]] .from> = 0) {Total = Data [Cur] [DATA [CUR] [END] .from] .dis; printf ("% c ->", DATA [CUR] [END] .FROM 65); CUR = Data [CUR] [END]. From;} Total = DATA [CUR] [END] .dis; printf ("% c / ntotal distance =% D", endCH (); return;}}

Void initdata (file * pfile) {char NUM [10]; INT i = 0; CHAR C; INT M, N; FSEEK (Pfile, 0, 0); for (m = 0;! Feof (Pfile) && m <7 ; M ) {for (n = 0; fEOF (Pfile) && n <7; n ) {while (! feof (pfile)) {c = fgetc (pfile); if (c == ',') / * read Final a number * / {NUM [i] = '/ 0'; DATA [M] [N] .dis = atoi (num); data [m] [n] .from = -1; i = 0; Break; } Else IF ((c> = '0' && c <= '9') || c == '-') / * If you read a number or symbol * / {NUM [i ] = C;}}} }

Void outputdata () {INT I, J; Printf (""); for (i = 0; i ", i);} printf ("/ n"); For (i = 0; i 0) / * If the Send node is available to the i node, there is a route * / { IF (Data [RECV] [i] .dis <0) / * If the RECV to I Node No Path * / {Data [Recv] [i] .dis = Data [Send] [i] .dis data [RECV ] [send] .dis; data [recv] [i] .from = send;} else if (data [recv] [i] .dis> data [send] [i] .dis data [rw) [send] .dis) / * If the existing path is much farther than the new path * / {data [recv] [i] .dis = data [send] [i] .dis data [recv] [send] .dis; data [recv] [i] .from = send;}}}}

Void Exchange () {INT I, J; for (i = 0; i 0) / * If there is a path between the two nodes * / {Communication (J, I); / * Send the routing table of the I node * /}}} / * Data.txt * / 0, 2 , -1, -1, 8, -1, 5, 2, 0, -1, 5, -1, -1, -1, -1, -1, 0, -1, -1, 9, -1 , -1, 5, -1, 0, -1, -1, -1, 8, -1, -1, -1, 0, -1, 7, -1, -1, 9, -1, - 1, 0, 3, 5, -1, -1, -1, 7, 3, 0,

转载请注明原文地址:https://www.9cbs.com/read-88706.html

New Post(0)