Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please fill up the given functions in C language which works in Visual Studio 2015 without any errors( do not need to write

Can you please fill up the given functions in C language which works in Visual Studio 2015 without any errors( do not need to write a different code separately, just write the code where it says "Add your code here"). Can someone jsut fill it up as my exams are next week, and I'm getting confused the way they have written the code. It will be a great help is someone just writes the code in the given format. I am posting this question the second time, as someone just sent kruskal's algorithm in java when i posted it the first time. i know i have to apply kruskal's algorithm into this, but i dont know how to do it in the skeleton code given. please fill up the skeleton code, i do not need any separate code

Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the function

the given code:

#include #include #include #include #include #define INFINITY 0 #define MAXNODE 26 // Pointer to the file you want to read and write. FILE *fp; int NumberOfNode = 0; // Initialize the Adjacency table **AM // In this function, you should set all elements in the Adjacency table to INFINITY void InitAM(int **AM) { //********* //Add your code here //********* //********* }

//Read the Graph from the input file to **AM // int ReadGraph(int **AM) { //open file fp = fopen("DataIn.txt", "r");

if (fp == NULL) { printf("Unable to open file."); return 0; } else { int i = 0; // get the number of nodes of the graph fscanf(fp, "%d ", &NumberOfNode);

for (; i< NumberOfNode; i++) { int NodeOfLine = 0; int NumberOfNodesLine = 0; int node = 0; int weight = INFINITY; //get the current node fscanf(fp, "%d", &NodeOfLine); if (NodeOfLine == (i + 1)) { int j = 0; //get the number of nodes connected to the current node fscanf(fp, "%d", &NumberOfNodesLine);

for (j = 0; j< NumberOfNodesLine; j++) { //get the weight of the link fscanf(fp, "%d", &node); fscanf(fp, "%d", &weight); AM[i][node] = weight; } fscanf(fp, " "); } else { return 0; } }

}

fclose(fp); return 1;

} //find the minimum spanning tree (MST) from **AM1, and store the MSP in **AM2 // int MPS_tree(int **AM1, int **AM2) { //********* //Add your code here //********* //********* }

//print out the minimum spanning tree in **AM, as specified in Q4 // void WriteMPS(int ** AM) { //********* //Add your code here //********* //********* } ///print out the graph in **AM, for testing // In this function, all you have to do is to print every element in the Adjacency table **AM // void WriteGraph(int ** AM) { //********* //Add your code here //********* //********* } int main() { //create two-dimensional array AM1, AM2 // int ** AM1 = (int **)malloc(sizeof(int *) * MAXNODE); int ** AM2 = (int **)malloc(sizeof(int *) * MAXNODE); int i; for (i = 0; i < MAXNODE; i++) { AM1[i] = (int *)malloc(sizeof(int) * MAXNODE); AM2[i] = (int *)malloc(sizeof(int) * MAXNODE); } InitAM(AM1); InitAM(AM2); if (ReadGraph(AM1) == 0) { return 1; } if (MPS_tree(AM1, AM2) == 0) { printf("There is no minimun spanning tree!"); return 1; } WriteMPS(AM2); for (i = 0; i < MAXNODE; i++) { free(AM1[i]); free(AM2[i]); } free(AM1); free(AM2); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

What tools might be helpful?

Answered: 1 week ago