void 
Dijkstra(int** adj_matrix, int num, int start, int dist[]) {
	int i, u, v;
	int id, key;
	bool* access = malloc(sizeof(bool) * num);
	struct PQueue* pq = create_pqueue(num);
	
	for (i = 0; i < num; i++) {
		if (i == start) {
			dist[i] = 0;
		}
		else {
			dist[i] = infinite;
		}
		access[i] = false;
		insert(pq, i, dist[i]);
	}

	for(i = 0; i < num; i++) {
		extract_min(pq, &u, &key);
		access[u] = true;
		for (v = 0; v < num; v++) {
			if (!access[v] && adj_matrix[u][v] && dist[v] > dist[u] + adj_matrix[u][v]) {
				dist[v] = dist[u] + adj_matrix[u][v];
				decrease_key(pq, v, dist[v]);
			}
		}
	}

	destroy_pqueue(pq);
	free(access);

}
Beispiel #2
0
/**
 * Destroy list of processes
 * @param plist List of processes in the system
 * @param pnum Number of processes in the system
 * @return 1 when sucessful, otherwise 0
 */
int destroy_processes(process plist, int pnum)
{
    if (plist == NULL) return 0;

    for(int i = 0; i < pnum; ++i) {
        destroy_pqueue(plist[i].recvd_from);
        free(plist[i].pending);
    }
    free(plist);

    return 1;
}