-
-
Notifications
You must be signed in to change notification settings - Fork 610
Suggestion/Feedback #684
Description
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;
}