vendredi 1 mai 2015

Comparing two randomly assigned integers

I'm trying to create an adjacency matrix which represents a directed graph. I would like to make sure that a vertex does not connect to itself so I wrote this bit of code which I believe would work, but i am still getting v3 connects to v3.

Here is the part of my code which would be of interest:

//outside of main

#include <ctime>

struct gNode{

bool connected;
bool visited;   

};

//inside main

srand(time(0));
for(int i = 0; i < 15; i++){
    size_t o,a;
    o=rand()%8;
    a=rand()%8;
    if(o!=a){g[o][a].connected = true;}}







 v1 v2 v3 v4 v5 v6 v7 v8 

v1 0 1 1 0 0 1 1 0
v2 0 0 1 0 0 1 1 0
v3 0 0 1 0 0 0 1 0
v4 1 0 1 0 0 0 1 0
v5 0 1 1 0 0 1 1 0
v6 0 0 1 0 0 0 0 0
v7 0 1 0 0 0 1 0 0
v8 0 0 1 1 0 1 1 0

Thank You :)




Aucun commentaire:

Enregistrer un commentaire