这恰恰std::min_element是为了:
std::array<std::list<Client*>, 10> arr;
auto it = std::min_element(arr.begin(), arr.end(),
[](const std::list<Client*>& a, const std::list<Client*>& b){
return a.size() < b.size();
});
Run Code Online (Sandbox Code Playgroud)
那会给你一个迭代器,其中list元素最少.
如果列表在您开始添加它们时从零元素开始并且您希望保持它们完全平衡,请考虑只添加循环样式列表:
伪代码:
index = 0
list to add to = lists[index % list length]
index++
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
86 次 |
| 最近记录: |