Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Suggestion/Feedback #684

@Hardik645

Description

@Hardik645

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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    feedbackInclude this label if you want to give feedbacksuggestionInclude this label if you want to suggest anything

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions