I have a vector A [9 3 6 9 3 6] each 2 elements represent the edge of a graph, I wan to create the adjacency matrix from this vector.
First i created the unique vector A [3 6 9] to know the size of my matrix
Second I create a matrix and fill it with 0
Third I will run a loop on A to know what edges are connected, my question is how can I tell C++ that the first element in A which is three actually represent element 0 in my matrix, same for 6 that it represent 1 and 9 is represented by 3, like this when I construct my adjacency matrix i know that 0 1 2 represent actually 3 6 9, I heard about using a map but didn t know how to construct it in my program because im new to C++.
You are essentially trying to track labels for your vertices. If each vertex has a sequentially assigned number, you can scan new vertex labels and insert the corresponding sequential number in a map, like so:
Now as you process your input, you read one label token
vat a time, send it tostore_vertex_label(), and you get the corresponding sequential vertex index back.Your adjacency matrix will be of size
labels.size()squared.Note that your label type doesn’t have to be an integer, it could be anything (e.g. a string).