c++ - a digraph representation by structs -
I want to make a diagram of I have a surround matrix [] [] and I want to read the matrix and create a new graph. Here's the code; ... ... () (int i = 0; i & lt; total node; i ++) {For (int j = 0; j and lt; total nodes; J ++) {if (adjacency matrix [i] [j] == 1) {struct edge edge; edgeij.destination = nodej; kinageri korig = Node; nodei- & gt; outgoing.push_back (edgeij); // ??? nodej- & gt; incoming.push_back (edgeij); //}}} I'm not familiar with C / C ++ Clearly I have some help to improve this How can I push_back a vector of the declared declaration in the struct? when you do : Since your vector is expecting the indicator, you use the dynamically allocated , to better design solutions, to completely avoid raw pointers, and smart pointers to choose, e.g. destination node and
original node in each edge . In addition, each node has information about the
incoming exit and
outgoing emails .
Structure node {vector & lt; Edge * & gt; IncomingEdges; Vector & lt; Edge * & gt; OutgoingEdges; }; (Int i = 0; i & lt; total node for the root edge (frame node destination; node origin;};
; I ++) {struct node node;}
if (proximity matrix [i] [j] == 1) {struct edge edge; edgeij.destination = nodej; kinaregi.corig = nodi; nodei-> outgoing.push_back (Edgeij); // ??? nodej- & gt; incoming.push_back (edgeij); // ???}
edge at the end of the block The object is destroyed, which makes it very useless (and the code is not compiled anyway, because you push it Trying the object where pointer is expected)
edge Should:
edge * edge = new border; Edgeij.destination = nodej; Kinaregi Korig = nodi; Nodei-> Outgoing.push_back (edgeij); Nodej- & gt; Incoming.push_back (edgeij); // Now, do not delete resources allocated with the new
std :: vector & lt; Std :: unique_ptr & lt; Node & gt; & Gt; .
Comments
Post a Comment