need help with Minimum spanning

Need help fixing code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>

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;
return (0);
}

1. You have no meaningful indentation in your code. It is difficult to see scopes.

2. Where in the code do you need help? What there is to fix? What errors (exactly) do you have? You will be a step closer to solving your problems on your own, when you learn to describe each issue.
Need help fixing code
The compiler you use compiles this code without any remark? www.cpp.sh shows:
 In function 'void minimumspanningtree(int*, int (*)[99], int, int)':
31:1: error: 'temp' was not declared in this scope
39:6: error: 'struct node' has no member named 'to'
42:3: error: 'temp' was not declared in this scope
 In function 'int main()':
67:31: error: cannot convert 'int (*)[7]' to 'int (*)[99]' for argument '2' to 'void minimumspanningtree(int*, int (*)[99], int, int)'
68:7: error: 'getch' was not declared in this scope
69:1: error: 'pnode' was not declared in this scope
69:12: error: 'temp' was not declared in this scope
Topic archived. No new replies allowed.