#include #include #include #include #define MALLOC(t,n) (t *) malloc( n*sizeof(t) ) #define MALLOC2D(t,n) (t **) malloc(n*sizeof(t) ) #define CHECKPTR(p) if (!p) Error("Out of memory") #define MAX_INT 999999999 int vertexNum; int **PATHS = (int**) NULL; //edgelerin uzunluklari int **ROUTE2 = (int**) NULL; //ROUTE mizi belirleriz int *SHORTEST_PATH = (int*) NULL; //o vertex in baslangica en kisa yolu int *VISITED = (int*) NULL; //Y a dahil olanlarý isaretlenmis gibi gosterecegiz ////////////////////////////////////// // // if any error occurs we can write it // ////////////////////////////////////// void Error (char *str) { printf("\nERROR: %s\n", str); return; } ////////////////////////////////////// // // rmy_vertexs the file and built the synamic structure // ////////////////////////////////////// void readFileBuiltStruct( char *str) { FILE *fpRead; int i,j; int num; fpRead = fopen(str, "r" ); //start to rmy_vertex the input.txt rewind ( fpRead ); fscanf ( fpRead, "%d", &vertexNum); //mallocations dynamicly and check for errors SHORTEST_PATH = MALLOC( int , vertexNum ); CHECKPTR( SHORTEST_PATH ); VISITED = MALLOC( int , vertexNum ); CHECKPTR( VISITED ); PATHS = MALLOC2D( int , vertexNum ); CHECKPTR( PATHS ); ROUTE2 = MALLOC2D( int , vertexNum ); CHECKPTR( ROUTE2 ); for(i=0; i PATHS[my_vertex][j] + SHORTEST_PATH[my_vertex] ) { //we found more shortest way.. change the old one SHORTEST_PATH[j] = PATHS[my_vertex][j] + SHORTEST_PATH[my_vertex]; for(k=0; k