Search
 
SCRIPT & CODE EXAMPLE
 

CPP

find the mminimum of the vector and its position in c++

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = {2, 1, 3, 6, 7, 9, 8};
 
    auto it = std::minmax_element(v.begin(), v.end());
    int min_idx = std::distance(v.begin(), it.first);
    int max_idx = std::distance(v.begin(), it.second);
 
    std::cout << min_idx << ", " << max_idx << std::endl; // 1, 5
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ array access operator 
Cpp :: how to replace a element in a vector c++ using index 
Cpp :: check if number is positive or negative in cpp 
Cpp :: c+ 
Cpp :: sinh to hop c++ 
Cpp :: Reading package lists... Done Building dependency tree Reading state information... Done mysql-server is already the newest version (5.7.36-0ubuntu0.18.04.1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 
Cpp :: c++ 
Cpp :: how to know how many numbers i deleted with erase command on multiset c++ 
Cpp :: c++ to c converter online 
Cpp :: interactive problem 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: lnk2001 unresolved external symbol __imp_PlaySoundA 
Cpp :: distructor of the node of the link list 
Cpp :: cuda allocate memory 
Cpp :: clang does not recognize std::cout 
Cpp :: racing horses codechef solution c++ 
Cpp :: Arduino Access Point ESP8266 
Cpp :: C++ Point to Every Array Elements 
Cpp :: online c++ graphics compiler 
Cpp :: const char * to std::wstring 
Cpp :: initializer before void c++ 
Cpp :: ex:c++ gcc start adress 
Cpp :: how to run a cpp file in visual studio 
Cpp :: how to convert n space separated integers in c++ 
Cpp :: c++ do you not inherit constructor 
Cpp :: C++ Counting 
Cpp :: c++ pwstr to char* 
C :: how to slow voice speed in pyttsx3 
C :: docker container give usb access 
C :: get window width height glfw 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =