#include <string>
#include <deque>
#include <iostream>
#include <algorithm>
using namespace std;
void print( deque<string> );
int main()
{
deque<string> dequeObject;
dequeObject.push_back( "yak" );
dequeObject.push_back( "zebra" );
dequeObject.push_front( "cat" );
dequeObject.push_front( "canary" );
print(dequeObject);
dequeObject.pop_front();
dequeObject.pop_back();
print(dequeObject);
//list operations on a deque:
dequeObject.erase(find( dequeObject.begin(), dequeObject.end(), "cat" ));
print(dequeObject);
dequeObject.insert( dequeObject.begin(), "canary" );
print(dequeObject);
int sz = dequeObject.size();
dequeObject.resize( 5 );
dequeObject[sz] = "fox";
dequeObject[sz+1] = "elephant";
dequeObject[sz+2] = "cat";
print( dequeObject );
dequeObject.erase( dequeObject.begin() + 2 );
print( dequeObject );
//sorting a deque:
sort( dequeObject.begin(), dequeObject.end() );
print( dequeObject );
return 0;
}
void print( deque<string> d ) {
typedef deque<string>::const_iterator CI;
cout << "The number of items in the deque:" << d.size() << endl;
for ( CI iter = d.begin(); iter != d.end(); iter++ )
cout << *iter << " ";
cout << endl << endl;
}
|