@@ -22,6 +22,47 @@ Pseudocodifica in C dell'algoritmo di Dijkstra con Esercizio di Default e Calcol
2222
2323<img width =" 300 " src =" https://github.com/vittorioPiotti/Algoritmo-Dijkstra-C/blob/main/snap.png " />
2424
25+
26+ ## Snippet Dijkstra Algorithm
27+
28+ ``` c
29+
30+ int dijkstra (struct ConnectedNodes connectedNodes[ ] , struct Paths paths[ ] , struct RoutingTables routingTables[ ] ,int start, int end,int nNodes){
31+ int i = 0;
32+ int j = 0;
33+ int inx = 0;
34+ int cost = 0;
35+ int nPaths = 1;
36+ for(i = 0; i < nNodes; i ++){
37+ if(routingTables[ 0] .routingTable[ i] .id == start)routingTables[ 0] .routingTable[ i] .cost = 0;
38+ }
39+ do{
40+ i = getInxMinCostNotExplored(routingTables[ 0] .routingTable,nNodes);
41+ routingTables[ 0] .routingTable[ i] .used = USED;
42+ if(routingTables[ 0] .routingTable[ i] .cost == MAX_COST + 1)cost = 0;
43+ else cost = routingTables[ 0] .routingTable[ i] .cost;
44+ if(connectedNodes[ i] .length != 0){
45+ for(j = 0; j < connectedNodes[ i] .length; j ++){
46+ inx = getInxRoutingTable(routingTables[ 0] .routingTable,connectedNodes[ i] .connections[ j] .id,nNodes );
47+ if(connectedNodes[ i] .connections[ j] .cost + cost < routingTables[ 0] .routingTable[ inx] .cost){
48+ routingTables[ 0] .routingTable[ inx] .cost = connectedNodes[ i] .connections[ j] .cost + cost;
49+ routingTables[ 0] .routingTable[ inx] .prec = connectedNodes[ i] .id;
50+ }else if(connectedNodes[ i] .connections[ j] .cost + cost == routingTables[ 0] .routingTable[ inx] .cost){
51+ routingTables[ nPaths] .routingTable[ inx] .cost = connectedNodes[ i] .connections[ j] .cost + cost;
52+ routingTables[ nPaths] .routingTable[ inx] .prec = connectedNodes[ i] .id;
53+ nPaths++;
54+ }
55+ }
56+ }
57+ }while(allExplored(routingTables[ 0] .routingTable,nNodes) == NOT_USED);
58+ if(nPaths > 1)fixRoutingTable(routingTables, nPaths, nNodes);
59+ initPaths(routingTables, paths, nPaths, nNodes, start, end);
60+ fixResults(routingTables, paths, nPaths, nNodes);
61+ return nPaths;
62+ }
63+
64+ ```
65+
2566## Licenze
2667
2768| Componente | Versione | Copyright | Licenza |
0 commit comments