Description: The header 'boost/range/algorithm/remove.hpp'contains the algorithm remove() in C++ boost library. This function rearranges all the occurrence from a sequence such that elements x from the range returns true for x == val. The function returns an iterator new_last such that [first, new_last) contains no elements equal to val. The range [new_last, last) consists of unspecified elements.
Parameters: The following parameters are accepted by the function: 1.) rng: It specifies the sequence whose elements as to be eliminated. 2.) val: The value to be removed.
The function returns an iterator new_last such that [first, new_last) contains no elements equal to val.
// remove all the occurrence of 5 from Arr auto Arr_new_size = boost::range::remove(Arr, 5); // remove all the occurrence of 1 from Arr1 auto Arr1_new_size = boost::range::remove(Arr1, 1); // Resizing the array to new_last Arr.resize(Arr_new_size - Arr.begin()); Arr1.resize(Arr1_new_size - Arr1.begin());
cout << "The elements of Arr after removing are: {"; for(auto it = boost::begin(Arr); it != boost::end(Arr); it++) cout << *it << " "; cout << "}";
cout << endl << "The elements of Arr1 after removing are: {"; for(auto it = boost::begin(Arr1); it != boost::end(Arr1); it++) cout << *it << " "; cout << "}"; }
Output: The elements of Arr after removing are: {1 2 9 7 } The elements of Arr1 after removing are: {}
Complexity:
Time Complexity: The time complexity is linear between the first and last elements. There are exactly distance(rng) number of comparisons performed.
Please write on comment section if you find any mistake or for any suggestions.
Comments