简体   繁体   中英

Most efficient way to clear array of vectors

I have a graph representation which looks like this

vector<int> Graph[MAXN]

Next, I want to remove all previously set vectors. What is the fastest way to do it ?

There's no real question of "efficiency" here. You must iterate through your array, and you must invoke std::vector<int>::clear() on each element of that array. So, just do it :

for (auto& v : Graph) {
   v.clear();
}

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