void organizeLists(std::vector<std::list<int>>& lists, std::vector<int>& output) { Comp comp; for (std::vector<std::list<int>>::iterator listMember=lists.begin(); listMember!=lists.end();) { if(listMember->empty()) { listMember = lists.erase(listMember); } else { ++listMember; } } if(!lists.empty()) { std::make_heap(lists.begin(), lists.end(), comp); while (!lists.empty()) { std::list<int> &temp = lists.front(); output.push_back(temp.front()); temp.pop_front(); if (temp.empty()) { lists.erase(lists.begin()); } std::make_heap(lists.begin(), lists.end(), comp); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)