ccplusplus.com
Learn C, C++ Concepts
Tuesday, January 10, 2012
remove algorithm
/*********************************************************************** * File : remove.cpp * Author : Saurabh Gupta * Desc : stl remove algorithm c++ * Source : http://ccplusplus/2011/10/standard-template-library.html * Created : PM 10:44 09 January 2012 * Note : this code is not fully operational as we expected. See * teh below link for the modified code * http://www.ccplusplus.com/2012/01/list-remove.html ************************************************************************/ #include <iostream> #include <list> #include <algorithm> #include <iterator> using namespace std; int main() { list<int> coll; //insert elements from 6 to 1 and 1 to 6 for (int i=1; i<=6; ++i) { coll.push_front(i); coll.push_back(i); } //print all elements of the collection cout << "pre: "; copy (coll.begin(), coll.end(), //source ostream_iterator<int> (cout," ")); //destination cout << endl; //remove all elements with value 3 remove (coll.begin() , coll.end(), //range 3); //value //print all elements of the collection cout << "post: "; copy (coll.begin(), coll.end(), //source ostream_iterator<int> (cout," ")); //destination cout << endl; } /* * OUTPUT * [sgupta@rhel6x64 algorithm]$ c++ remove.cpp -o remove [sgupta@rhel6x64 algorithm]$ ./remove pre: 6 5 4 3 2 1 1 2 3 4 5 6 post: 6 5 4 2 1 1 2 4 5 6 5 6 [sgupta@rhel6x64 algorithm]$ */
See Also:
Standard Template Library Concepts and sample codes in C++
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment