From C++11 onwards, some new and interesting algorithms are added in STL of C++. These algorithms operate on an array and are useful in saving time during coding and hence useful in competitive programming as well.
This function operates on whole range of array elements and can save time to run a loop to check each elements one by one. It checks for a given property on every element and returns true when each element in range satisfies specified property, else returns false.
All are not positive elements
In the above code, -6 being a negative element negates the condition and returns false.
This function checks for a given range if there’s even one element satisfying a given property mentioned in function. Returns true if at least one element satisfies the property else returns false.
There exists a negative element
In above code, -6 makes the condition positive.
This function returns true if none of elements satisfies the given condition else returns false.
No negative elements
Since all elements are positive, the function returns true.
copy_n() copies one array elements to new array. This type of copy creates a deep copy of array. This function takes 3 arguments, source array name, size of array and the target array name.
The new array after copying is : 1 2 3 4 5 6
In the above code, the elements of ar are copied in ar1 using copy_n()
This function is used to assign continuous values to array. This function accepts 3 arguments, the array name, size, and the starting number.
The new array after assigning values is : 20 21 22 23 24 25
In the above code, continuous values are assigned to array using iota().
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- numeric header in C++ STL | Set 2 (adjacent_difference(), inner_product() and iota())
- std::iota in C++
- array::front() and array::back() in C++ STL
- array::fill() and array::swap() in C++ STL
- array::begin() and array::end() in C++ STL
- array::crbegin() and array::crend() in C++ STL
- array::cbegin() and array::cend() in C++ STL
- array::rbegin() and array::rend() in C++ STL
- <algorithms> library in C++ STL
- Program to find if two numbers and their AM and HM are present in an array using STL
- Sorting an array according to another array using pair in STL
- Count the number of 1's and 0's in a binary array using STL in C++ ?
- Finding Floor and Ceil of a Sorted Array using C++ STL
- Working with Array and Vectors using STL in C++
- How to find the minimum and maximum element of an Array using STL in C++?
- Elements present in first array and not in second using STL in C++
- Find elements of an Array which are Odd and Even using STL in C++
- Sorting Array Elements By Frequency | Set 3 (Using STL)
- Array sum in C++ STL
- array::operator[ ] in C++ STL
Improved By : mohitw16