Hi, i am trying to create a vector a structure type
my code so far is
Code:
struct WEdge
{
vector<int>From; // an array for u points
vector<int>To; // an array for v points
vector<int>Weight; // an array for w points
};
WEdge edges;
edges.From.push_back(1);
edges.To.push_back(2);
edges.Weight.push_back(5);
this allows me to add elements, but seems weird considering other example on the internet.
but i think i shouldnt be doing it like this and should instead do something like
Code:
struct WEdge
{
int From; // an array for u points
int To; // an array for v points
int Weight; // an array for w points
};
vector<WEdge> edges;
..
but when i do it this way i cant seem to add data using push_back method.
also i later need to be able to sort the data by the Weight, but move the from and to values along with the weight when sorting.
please clarify which method will be better for me.
----------------------------------------------------------
also, i have tried sorting using
Code:
std::sort(edges.Weight.begin(), edges.Weight.end());
but this only sorts the Weight and leaves the From and To values in the same place.
thanks