Finding smallest value in an array most efficiently

后端 未结 13 1687
慢半拍i
慢半拍i 2020-11-29 07:02

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently?

13条回答
  •  天命终不由人
    2020-11-29 07:48


    Procedure:

    We can use min_element(array, array+size) function . But it iterator
    that return the address of minimum element . If we use *min_element(array, array+size) then it will return the minimum value of array.


    C++ implementation

      #include
      using namespace std;
    
      int main()
      {
         int num;
         cin>>num;
         int arr[10];
    
         for(int i=0; i>arr[i];
         }
    
    
        cout<<*min_element(arr,arr+num)<

提交回复
热议问题