Reputation: 157
I have a vector of size four and want to be able to iterate through it extract the smallest value on each iteration and assign it to a variable.
vector <double> vs;
int a;
int b;
int c;
int d;
vs.push_back(1); vs.push_back(2); vs.push_back(3); vs.push_back(4);
and I want a= 1, b=2, c=3, d=4. Whats the best way to do this?
Upvotes: 0
Views: 188
Reputation: 791531
It's probably easiest to sort the vector
(using std::sort
) - or a copy of the vector if you need to preserve the original vector - and assign a = vs[0]
, b = vs[1]
, etc.
Upvotes: 3