Floyd-Warshall algorithm: Difference between revisions
m
→{{header|C}}
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|C}}) |
||
Line 1,370:
</pre>
==={{libheader|Gadget}}===
VERSION 2. Using Gadget, an a "C" library.
<syntaxhighlight lang="c">
#include<limits.h>▼
#include
LIB_GADGET_START
/* algunos datos globales */
Line 1,379 ⟶ 1,384:
/* algunos prototipos */
F_STAT DatosdeArchivo( const char *cFile);
int *
int *
▲int * CargaGrafo(int * graph, DS_ARRAY * graph_data, char *cFile);
void Floyd_Warshall(int * graph, DS_ARRAY graph_data);
/* bloque principal */
Main
if ( Arg_count != 2 ){
GetArgStr(cFile,1);▼
Msg_yellow("Modo de uso:\n ./floyd <archivo_de_vertices>\n");
SetTokSep(' ');▼
Cls;
if(
New
graph = CargaGrafo(
if(graph){
/* calcula Floyd-Warshall */
Floyd_Warshall( SDS(graph
Free
}
}else{
}
Free
End
void Floyd_Warshall( RDS(int
Array
Fill array processWeights as int(vertices,vertices) with SHRT_MAX;
int i,j,k;
MAT( processedVertices ) = (i!=j)?j+1:0; ); ▼
Compute_for( processWeights, i,j,
#define VERT_ORIG 0
Line 1,421 ⟶ 1,432:
#define WEIGHT 2
$2processWeights[ $graph[i,VERT_ORIG]-1, $graph[i,VERT_DEST]-1 ] = $graph[i,WEIGHT];
}▼
Compute_for (processWeights,i,j,
// ya existen rangos definios para "processWeights":
Compute_for(processWeights, i, j,
▲ {
Print
}while(k!=j+1);
}
);
Free
}
F_STAT DatosdeArchivo( const char *cFile){
return
}
int * CargaMatriz( pRDS(int, mat), const char * cFile, F_STAT stat ){
}
int *
▲ return LoadMatrix_int( mat, mat_data, cFile, stat);
F_STAT dataFile = DatosdeArchivo(cFile);
if(dataFile.is_matrix){
graph = CargaMatriz( SDS(graph), cFile, dataFile);
if( graph ){
/* obtengo vertices = 4 y edges = 5 */
edges = dataFile.total_lines;
}else{
}
}else{
}
return graph;
|