简体   繁体   中英

How can you Iterate through vector and extract smallest value on each iteration

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?

排序vector (使用std::sort )最简单-如果需要保留原始向量,则可以复制向量的副本-并分配a = vs[0]b = vs[1]等。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM