Hey everyone i was wondering if i could help me out. Im trying to count the weight in each row of this adjacency matrix, but i cannot figure out a way to add up one row at a time. Here what i have for my weight method
//These variables represent the row and coll of the graph
int i, j;
//These variables are used for counting odd and even weights, and the sum
int numEven = 0;
int numOdd = 0;
int sum = 0;
int row_number = 1;
int column_number = 1;
//Begin loop to get weights of graph and then add them
for (i=0;i<row_number;i++)
{
sum = 0;
for (j=0; j<column_number;j++)
{
cout<<" "<<edge(i,j)<<endl;
sum +=edge(i,j);
if (edge(i,j) < infiniteEdgeWt) //Used so that 9999 isnt added or displayed
{
if(sum%2 == 0)
{
numEven += 1;
cout<<i<<" even\n";
}
else
{
numOdd += 1;
cout<<i<<" odd\n";
}
}
}
}
cout<<"Number of Even Degree Vertices = "<<numEven<<endl;
cout<<"Number of Odd Degree Vertices = "<<numOdd<<endl;
Whats supposed to happen is a graph is loaded, and then i can make a call to the weight method. from there the for loop0 call edge(i,j) and return the weight of each column and row. but whats happening is for each weight the loop is applying the odd and even check. i want that to happen after each rows numbers are retrieved, and then move onto the next.
void WtGraph:: degree()
{
//These variables represent the row and coll of the graph
int i, j;
//These variables are used for counting odd and even weights, and the sum
int numEven = 0;
int numOdd = 0;
int sum = 0;
int row_number = 8;
int column_number = 8;
//Begin loop to get weights of graph and then add them
for (i=0;i<=row_number;i++)
{
sum = 0;
for (j=0; j<=column_number;j++)
{
if (edge(i,j) < infiniteEdgeWt) //Used so that 9999 isnt added or displayed
{
sum += edge(i,j);
}
}
//IF statements to check for odd and even weights per row
if(sum%2 == 0)
{
numEven += 1;
cout<<"ROW "<<i<<" even\n";
}
else
{
numOdd += 1;
cout<<i<<" odd\n";
}
}
//Output number of odd and even degree's
cout<<"Number of Even Degree Vertices = "<<numEven<<endl;
cout<<"Number of Odd Degree Vertices = "<<numOdd<<endl;
}