|
-
June 25th, 2008, 11:28 AM
#1
cyclomatic complexity help needed
hey everyone i really need your help in any way possible.
i am new to c++ but i have a very hard assignment for my understanding.
i need to implement cyclomatic complexity.
i know that program needs to use the adj matrix like this for instance:
1 0 1 0
0 0 1 0
1 1 0 0
1 0 0 0
i need to use BFS to traverse through the nodes and find all the possible paths from beginning to the end as well as all the predicate nodes in this example there are 2 of them 1 0 1 0 and 1 1 0 0
so Cyclomatic Complexity should be 2 + 1 = 3
i actually managed to implement something so here it is:
Code:
#include <iostream>
using namespace std;
#define MAX 100
class BFS
{
private : int n;
int adj[MAX][MAX];
int visited[MAX];
public : void bfs(int);
void readmatrix();
};
void BFS :: readmatrix()
{
int i,j;
cout << "\nEnter the number of Vertices in the Graph : ";
cin >> n;
cout << "\nEnter the Adjacency Matrix\n\n";
for (i = 1; i <= n; i++)
for (j = 1; j<= n; j++)
cin >> adj[i][j];
for (i = 1; i <= n; i++)
visited[i] = 0;
}
void BFS :: bfs(int source)
{
int queue[MAX];
int i, front, rear, root;
front = rear = 0;
visited[source] = 1;
queue[rear++] = source;
cout << source << " ";
while (front != rear)
{
root = queue[front];
for (i = 1; i <= n; i++)
if (adj[root][i] && !visited[i])
{
visited[i] = 1;
queue[rear++] = i;
cout << i << " ";
}
front++;
}
}
int main()
{
int startNode;
BFS breadth;
breadth.readmatrix();
cout << "\nEnter the start node : ";
cin >> startNode;
cout << "\nThe nodes visited in the BFS order is : ";
breadth.bfs(startNode);
return 0;
}
this code asks you how many verticies the graph has then asks you to type up the matrix and then enter the start node...
after which it should print out all the paths possible... but in my case it prints out only one...
can someone please tell me what is wrong with my bfs ...
Last edited by eidalina20; June 25th, 2008 at 12:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|