### C++ std::replace for array

/**C++ std::replace for array**/
/** This algorithm is about to replace any number from a array with a new value. This is a simple STL base algorithm. This replace() function is define in 'algorithm' headerfile. Function Template: replace(initial_ndex, last_index, old_value, new_value); initial_index = it indicates base index of the array; last_index = it indicates last index of the array; old_value = it indicates old value of the array the need to replace; new_value = it indicates a new value that will be inserted in place of old value; **/ Algorithm: #include<bits/stdc++.h> #include<algorithm> using namespace std; int main () { int arr[]={10,20,10,80,50,10,46,51,26,10,50,64}; int n=sizeof(arr)/sizeof(arr[0]); //Elements before calling replace() function; cout << "Elements before calling replace() function: " << endl; for(int i=0;i<12;i++) cout << arr[i] << " "; cout << '\n'; //Calling replace() function; replace(arr, arr+n, 10,5); //Elements after calling replace_copy function; cout << "Elements after calling replace() function: " << endl; for(int i=0;i<12;i++) cout << arr[i] << " "; return 0; } /** Output: Elements before calling replace() function: 10 20 10 80 50 10 46 51 26 10 50 64 Elements after calling replace() function: 5 20 5 80 50 5 46 51 26 5 50 64 **/

#### More Articles of Ezaz Hossain Sardar:

Name Views Likes
Python Program to Find the first Common Element between the 2 given Linked Lists 254 20
C++ std::valarray_function_name 320 23
C++ std::typeindex_function_name 220 14
C++ std::condition_variable 298 16
C++ mutex mutex_function_name 298 24
C++ std:: 234 20
C++ std::is_trivially_default_constructible 294 20
C++ std::is_trivially_copy_constructible 301 29
C++ std::is_signed 294 25
C++ std::is_scalar 246 15
C++ std::is_same 323 22
C++ std::is_rvalue_reference 269 15
C++ std::is_reference 212 17
C++ std::is_object 257 15
C++ std::is_nothrow_destructible 334 26
C++ std::is_nothrow_constructible 300 22
C++ std::is_member_pointer 240 16
C++ std::is_member_function_pointer 263 19
C++ std::is_literal_type 305 26
C++ std::is_fundamental 261 16
C++ std::is_compound 267 20
C++ std::move for list 297 29
C++ std::move for array 287 22
C++ std::move 273 20
C++ std::replace for array 853 17
C++ std::replace 295 20
C++ std::replace_if 296 22
C++ std::minmax 325 27
C++ std::minmax_element 299 11
C++ std::remove 241 12
C++ std::remove_if 265 18
C++ std::replace_copy 253 20
C++ std::replace_copy_if 234 11
C++ std::remove_copy 271 19
C++ program to find get level of a node in binary tree using recursion 273 28
C++ program to find size of a tree without using recursion 202 14
C++ program to find height of a tree without using recursion 210 17
C++ program to find diameter of a binary tree in O(n) 269 23
C++ program to find diameter of a binary tree 245 13
C++ program to find height of a tree using recursion 215 17
C++ program to count non-leaf nodes in a binary tree using recursion 320 19
C++ program to count leaf nodes in a binary tree using recursion 671 13
C++ program to find sum of all leaf nodes of binary tree 250 21
C++ program to find sum of all the parent nodes having child node x 402 23
C++ program to print path from root to a given node in a binary tree 245 16
C++ program to find distance from root to given node in a binary tree 264 18