hi guys. How can create a code to display the beighbors of each vertex in a graph. for example the neighbor of 0 is 0,3
neighbor if 1 is 0. Youll see the neighbors in the matrix
Here is my code. Let me know if you need the header also.
:O is somebody trying to make an efficient Hamilton Circuit algorithm? :D
Make a class called Vertex, which has a member called std::string name, so that you can keep track of your vertices, then a std::vector<Vertex> neighbors of the neighbor points. Then make a class called Edge which has the members Vertex start, Vertex end, and int weight.
So then your prog would work like this:
1 2 3 4 5 6 7
graph<int> t;
Vertex a("A"); //param in constructor should set member "name" to "A";
Vertex b("B");
t.addVertex(a);
t.addVertex(b);
Edge a_to_b(a, b, 10); //a as start vertex, b as end vertex, 10 as weight
t.addEdge(a_to_b);
And for t.addEdge:
1 2 3 4 5 6
Graph::addEdge(Edge e) //type: void
{
graphEdges.push_back(e); //assuming all the edges are stores in a std::vector<Edge>
t.addVertexNeighbor(e.start, e.end);
t.addVertexNeighbor(e.end, e.start);
}