digraph/directed_graph.c
/*
 * This function creates an adjacency matrix of the vertices in the DirectedGraph struct
 * and has the graph's adjacencyMatrix struct variable point to this allocated adjacency matrix.
 */
This function creates an adjacency matrix of the vertices in the DirectedGraph struct
and has the graph's adjacencyMatrix struct variable point to this allocated adjacency matrix.
This function creates an adjacency matrix of the vertices in the DirectedGraph struct and has the graph ' s adjacencyMatrix struct variable point to this allocated adjacency matrix .
void create_adjacency_matrix(DirectedGraph* graph)
{
	if(graph == NULL)
		return;
	LinkedList* vertices = get_vertices(graph);
	int n                = digraph_size(graph);
	float** adjMtx = (float**) malloc( n * sizeof(float*));
	for(int i = 0; i < n; i++)
	{
		adjMtx[i] = (float*) malloc(n * sizeof(float));
		Vertex* source = linked_list_get(vertices, i);
		for(int j = 0; j < n; j++)
		{
			Vertex* destination = linked_list_get(vertices, j);
			if(has_arc_to_vertex(source, destination))
			{
				adjMtx[i][j] = get_weight(source, destination);
			} else {
				adjMtx[i][j] = FLT_MAX;
			}	
		}
	}
	graph->adjacencyMatrix = &adjMtx[0];
}
void create_adjacency_matrix ( DirectedGraph * graph ) { if ( graph == NULL ) return ; LinkedList * vertices = get_vertices ( graph ) ; int n = digraph_size ( graph ) ; float * * adjMtx = ( float * * ) malloc ( n * sizeof ( float * ) ) ; for ( int i = 0 ; i < n ; i ++ ) { adjMtx [ i ] = ( float * ) malloc ( n * sizeof ( float ) ) ; Vertex * source = linked_list_get ( vertices , i ) ; for ( int j = 0 ; j < n ; j ++ ) { Vertex * destination = linked_list_get ( vertices , j ) ; if ( has_arc_to_vertex ( source , destination ) ) { adjMtx [ i ] [ j ] = get_weight ( source , destination ) ; } else { adjMtx [ i ] [ j ] = FLT_MAX ; } } } graph -> adjacencyMatrix = & adjMtx [ 0 ] ; }
This function creates an adjacency matrix of the vertices in the DirectedGraph struct
 and has the graph's adjacencyMatrix struct variable point to this allocated adjacency matrix.
This function creates an adjacency matrix of the vertices in the DirectedGraph struct and has the graph ' s adjacencyMatrix struct variable point to this allocated adjacency matrix .
// If the graph parameter is NULL, return immediately. // Retrieve the vertex list and size of the graph struct parameter. // Declaring the adjacency matrix variable to hold n arrays of n elements.  // For each vertex in the vertex list. // Allocate memory for the array in row i. // Retrieve the source vertex at index i. // For each vertex in the vertex list. // Retrieve the destination vertex at index j; // If there is an arc from the source to destination vertex. // Then add the weight of this arc to the adjacency matrix at index i,j. // Otherwise thre is no arc, therefore add the maximum float value to index i,j. // Assign graph's adjacency matrix pointer to the first element of this calculated adjacency matrix.