adjacency matrix row loop

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

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
//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.

Hope that makes sense!
Never mind i figured it out, i feel so air headed.

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
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;

}
Topic archived. No new replies allowed.