All pastes #814082 Raw Edit

Mine

public text v1 · immutable
·published 2007-12-12 23:57 UTC
rendered paste body
void Dijkstra(GraphRef G, int s) {
	if(G == NULL) {
		printf("Graph.c Dijkstra() NULL arugment \n");
		exit(1);
	}
	if((s < 1 || s > G->order)) {
		printf("Graph.c Dijkstra() precondition not met. \n");
		exit(1);
	}
	
	
	initializeSingleSource(G, s);
	PriorityQueueRef Q = newPriorityQueue(G->order, G->distances);
	
	while(getNumElements(Q) > 0) {
		int u = getMin(Q);
		
		if(!isEmpty(G->Adj[u])) {
			for(moveFirst(G->Adj[u]); !offEnd(G->Adj[u]); moveNext(G->Adj[u])) {
				int v = getCurrent(G->Adj[u]);
				
				/*printf("\n\nChecking if %d is inside.\n", v);*/
				/*printPriorityQueue(Q, NULL);*/
				relax1(G, u, v, Q);
			}
		}
		
		deleteMin(Q);
	}
	
	/*printPriorityQueue(Q, NULL);*/
	freePriorityQueue(&Q);
}