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
|
#include <iostream>
using namespace std;
#define matrix( M, N ) M[ N * N ]
#define index( M, N, i, j ) (M)[ (j * N) + i ]
int maximal_degree( int matrix( M, 1 ), int N )
{
int result = 0;
for (int i = 0; i < N; i++)
{
int deg_i = index( M, N, i, i ); // loops get counted twice
for (int j = 0; j < N; j++)
deg_i += index( M, N, i, j );
if (deg_i > result)
result = deg_i;
}
return result;
}
int main()
{
int matrix( A, 3 ) =
{
0, 0, 1,
0, 0, 1,
1, 1, 1
};
cout << "The maximal degree of A is " << maximal_degree( A, 3 ) << " (should be 4)\n";
return 0;
}
|