c(pp)/dijkstra-sequential-example.c
// Dijkstra's algorithm; taking a graph, its dimension and the starting point
Dijkstra's algorithm; taking a graph, its dimension and the starting point
Dijkstra ' s algorithm ; taking a graph its dimension and the starting point
void dijkstra(int graph[DIM][DIM], int start){
	int i, j, k, temp, count, minDistance, next;
	int distance[DIM], parent[DIM], path[DIM];
	bool visited[DIM];
	for (i = 0; i < DIM; i++){
		distance[i] = graph[start][i]; 
		parent[i] = 0; 
		visited[i] = false; 
		path[i] = INF;
	}
	distance[start] = 0; 
	visited[start] = true; 
	for (i = 0; i < DIM; i++){
		minDistance = INF; 
		for (j = 0; j < DIM; j++){
			if (!visited[j]){
				if (distance[j] < minDistance){
					minDistance = distance[j]; 
					next = j; 
				}
			}
		}
		visited[next] = true;
		printf("distance:\t");
		printVector(distance);
		for (j = 0; j < DIM; j++){
			if (!visited[j]){
				temp = graph[next][j];
				if (minDistance + temp < distance[j]){
					distance[j] = minDistance + temp;
					parent[j] = next;
				}
			}
		}
		printf("distance:\t");
		printVector(distance);
	}
	printf("Adjacency matrix:\n-----------------\n");
	printMatrix(graph);
	printf("\n\n");
	printf("Paths:\n------");
	for (i = 0; i < DIM; i++){
		printPath(i, start, path, parent, distance);
	}
	printf("\n");
	return;
}
void dijkstra ( int graph [ DIM ] [ DIM ] , int start ) { int i , j , k , temp , count , minDistance , next ; int distance [ DIM ] , parent [ DIM ] , path [ DIM ] ; bool visited [ DIM ] ; for ( i = 0 ; i < DIM ; i ++ ) { distance [ i ] = graph [ start ] [ i ] ; parent [ i ] = 0 ; visited [ i ] = false ; path [ i ] = INF ; } distance [ start ] = 0 ; visited [ start ] = true ; for ( i = 0 ; i < DIM ; i ++ ) { minDistance = INF ; for ( j = 0 ; j < DIM ; j ++ ) { if ( ! visited [ j ] ) { if ( distance [ j ] < minDistance ) { minDistance = distance [ j ] ; next = j ; } } } visited [ next ] = true ; printf ( " \t " ) ; printVector ( distance ) ; for ( j = 0 ; j < DIM ; j ++ ) { if ( ! visited [ j ] ) { temp = graph [ next ] [ j ] ; if ( minDistance + temp < distance [ j ] ) { distance [ j ] = minDistance + temp ; parent [ j ] = next ; } } } printf ( " \t " ) ; printVector ( distance ) ; } printf ( " \n \n " ) ; printMatrix ( graph ) ; printf ( " \n \n " ) ; printf ( " \n " ) ; for ( i = 0 ; i < DIM ; i ++ ) { printPath ( i , start , path , parent , distance ) ; } printf ( " \n " ) ; return ; }
Dijkstra's algorithm; taking a graph, its dimension and the starting point
Dijkstra ' s algorithm ; taking a graph its dimension and the starting point
// loop 1: initializing // vector of distances from start to adjescent nodes  // no exisiting parents yet // no nodes visited yet // set distance of start node to itself to zero /* not necessary, since zero is minDistance anyway;
	circumvents the second if statement in loop 3 */ // loop 2: iterating over number of nodes // initializing minimum distance in every iteration /* loop 3: finding node with lowest distance value in distance vector
		(if node was not already visited); already processed nodes are
		excluded according to their visited status (true) */ // minimal distance value // index of the closest node /* closest node in current distance list is found and thus given a
		processed flag, which will leave it untouched in further iterations */ /* loop 4: updating the distance vector with distances from next node 
		(graph[next][j]) -> including new connections (replacing INF) and
		shorter indirect paths; by adding the minDistance we keep track of the 
		distance already travelled w.r.t the start node; already processed
		nodes must again be excluded */ // printing