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

Suggestion/Feedback #684

Open
Hardik645 opened this issue Oct 6, 2022 · 0 comments
Open

Suggestion/Feedback #684

Hardik645 opened this issue Oct 6, 2022 · 0 comments
Labels
feedback Include this label if you want to give feedback suggestion Include this label if you want to suggest anything

Comments

@Hardik645
Copy link

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;

}

@Hardik645 Hardik645 added feedback Include this label if you want to give feedback suggestion Include this label if you want to suggest anything labels Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feedback Include this label if you want to give feedback suggestion Include this label if you want to suggest anything
Projects
None yet
Development

No branches or pull requests

1 participant