GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, December 18, 2010

C++ STL - Using List

For using list, you use declare it like you declare vector or deque.

>> list data;            // use generic type

To insert an element to the data, you either use:
>> data.push_back("lady gaga");      // place at the last
or 
>> data.push_front("luna maya");      // place at the first

To get the size of the data, use:
>> cout << data.size();

To delete an element, use either:
>> data.pop_back();             // delete the last element
or
>> data.pop_front();             // delete the first element


There's no way to get access toward an element, but either:
>> cout << data.front();         // get the first element
or
>> cout << data.back();          // get the last element

         

Share/Bookmark

No comments:

Post a Comment