Question

Please help me with this C++ I would like to create that uses a minimum spanning tree algorithm in C++. I would like the program to graph the edges with weights that are entered and will display the r...

Please help me with this C++

I would like to create that uses a minimum spanning tree algorithm in C++. I would like the program to graph the edges with weights that are entered and will display the results.

The contribution of each line will speak to an undirected edge of an associated weighted chart. The edge will comprise of two unequal non-negative whole numbers in the range 0 to 99 speaking to diagram vertices that the edge interfaces. Each edge will have a doled out edge weight. The edge weight will be a positive whole number in the range 1 to 99. The three whole numbers on each info line will be isolated by space. An information line containing the string "end-of-document" will flag the finish of the diagram edge input. After the edge data is perused, the base crossing tree procedure will start. Utilize a cluster with a limit of 100 for account input edges. The info information is thought to be substantial. There is no compelling reason to perform information approval on the information

After the edges of the base spreading over tree are resolved, the edges will be shown on the support, one edge for every yield line, following the message: "Least crossing tree:". The edges of the base crossing tree will at that point be shown one edge for every line. Each yield line speaking to an edge will contain three whole numbers isolated by space. The initial two numbers will be the two vertices speaking to an edge of the base crossing tree. The third number will speak to the heaviness of the edge.

In the wake of showing the edges of a base spreading over the tree, the program will show the message: "Edge weight complete:" following y the sum of the weights from the edges comprising the minimum spanning tree

I.e

1 3 5

3 4 6

1 4 7

end-of-file

Sample output expected after processing the above input will be as follows:

Minimum spanning tree: 1 3 5

3 4 6

Edge weight total: 11

Please also include the following features

1-the input graph edges are read from a text data file;

2- output of the minimum spanning tree graph edges are written to a text data file;

3- the input and output file names are provided as command line parameters

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using namespace std;
struct node
{
int source, dest, cost;
}n[9];

int c = 0, tempnode1= 0, tempnode2 = 0;

void minimumspanningtree(int *a, int b[][99], int i, int j)
{
a[i] = 1;
while (c < 9)
{
int min = 999;
for (int i = 0; i < 9; i++)
{
if (a[i] == 1)
{
for (int j = 0; j < 7; )
{
if (b[i][j] >= min || b[i][j] == 0)
{
j++;
}
else if (b[i][j] < min)
{
min = b[i][j];
temp = i;
tempnode1= j;
}
}
}
}
a[tempnode1] = 1;
n[c].source= tempnode2 ;
n[c].to = tempnode1;
n[c].cost = min;
c++;   
b[temp][tempnode1] = b[tempnode1][temp]=1000;
}
for (int k = 0; k < 6; k++)
{
cout<<"Minimum Spanning Tree"<<n[k].source<<"";
cout<<" "<<n[k].dest;
cout<<"Edge weight "<<n[k].cost<<endl;
}
}
int main()
{
int a[7];
for (int i = 0; i < 7; i++)
{
a[i] = 0;
}
int b[7][7];
for (int i = 0; i < 7; i++)
{
cout<<"enter values for "<<(i+1)<<" row"<<endl;
for (int j = 0; j < 7; j++)
{
cin>>b[i][j];
}
}
minimumspanningtree(a, b, 0, 0);
getch();
}pnode = 0, temp = 0;

Add a comment
Know the answer?
Add Answer to:
Please help me with this C++ I would like to create that uses a minimum spanning tree algorithm in C++. I would like the program to graph the edges with weights that are entered and will display the r...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT