Question: In C /* This function constructs an adjacency list for a graph from an adjacency matrix input parameters: The following are 'consumed' by this function

In C

/* This function constructs an adjacency list for a graph from an adjacency matrix input parameters: The following are 'consumed' by this function int** adj_mat 2D array that stores the adjacency matrix int rows # of rows in the matrix int cols # of columns in the matrix

The following are 'produced' by this function adj_node_t*** list a linked list of adjacencies

return parameters: none

adj_node_t*** list is passed in by reference from the main function so that it can be malloc'd via the init_adj_list function. After initializing it go through each row and add its adjacent nodes */ void construct_adj_list(int** adj_mat, int rows, int cols, adj_node_t*** list) { // verify that the adj matrix is correct if(rows != cols) { fprintf(stderr, "Adjacency matrix is not square "); exit(EXIT_FAILURE); } fprintf(stdout, "Constructing the adjacency list for this graph ... ");

// Initialize the linked list init_adj_list(list, rows);

// Since list was passed in by reference, accessing its // elements would require dereferencing it every time. // To make it easier, create a copy of the dereferenced // list and store it in myList for use in this function adj_node_t** myList = *list;

// INSERT YOUR CODE HERE // HINT: You will need to use create_node() and add_node() here // Go through each vertex and construct its adjacency list

fprintf(stdout, "done "); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!