How to maintain 2 lists of object

Posted by michael on Stack Overflow See other posts from Stack Overflow or by michael
Published on 2010-04-22T21:01:41Z Indexed on 2010/04/22 21:03 UTC
Read the original article Hit count: 168

Filed under:
|

Hi,

My c++ program needs to maintain 2 list of objects. list inuse; list free;

So objects A can even in 'inuse' list or in 'free' list, but not both. http://www.cplusplus.com/reference/stl/list/

I am think of using 'list' as the data structure for my lists. My questions are 1. why i can't randomly access an elmenet in the list, I look at the above api, I don't see a way to get inuse[2]; 2. How can I remove an element in the list? There is an erase(), but how can I use it to remove element #2? And after I remove element 2? will STL list fill the erased spot automatically? e.g. #3 will become #2, #4 will become #3 and so on?

Thank you.

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl