GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, December 18, 2010

C++ STL - Using Deque

Deque is Double Ended Queue. It's a vector, but has double ended - at back also at front.

>> deque data;       // use generic type

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

To access an element, you use [ ] operator:
>> cout << data[0];

To get how many elements in the queue:
>> cout << data.size();

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

   
Share/Bookmark

No comments:

Post a Comment