This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
Suggestion/Feedback #684
Labels
feedback
Include this label if you want to give feedback
suggestion
Include this label if you want to suggest anything
I am pulling a request to add distance function that is in algorithm header file
distance (start-iterator, final position)– It returns the distance of desired position from the first iterator.This function is very useful while finding the index.
Code(c++):
// C++ program to demonstrate working of distance()
#include
#include
#include
using namespace std;
int main()
{
// Initializing vector with array values
int arr[] = {5, 10, 15, 20, 20, 23, 42, 45};
int n = sizeof(arr)/sizeof(arr[0]);
vector vect(arr, arr+n);
// Return distance of first to maximum element
cout << "Distance between first to max element: ";
cout << distance(vect.begin(),
max_element(vect.begin(), vect.end()));
return 0;
}
The text was updated successfully, but these errors were encountered: