Home  >  Article  >  Database  >  2.11 最近点对

2.11 最近点对

WBOY
WBOYOriginal
2016-06-07 15:43:151155browse

一维数组总共包含N个数,求两数最小的差 double MinDifference(double arr[],int n) { if(n2) return 0; double fMinDiff=fabs(arr[0]-arr[1]); for(int i=0;in;i) for(int j=i1;jn;j) { double tmp=fabs(arr[i]-arr[j]); if(fMinDifftmp) { fMinDiff=tmp; }

一维数组总共包含N个数,求两数最小的差值

 

double MinDifference(double arr[],int n)

{

if(n

return 0;

 

double fMinDiff=fabs(arr[0]-arr[1]);

 

for(int i=0;i

    for(int j=i+1;j

    {

         double tmp=fabs(arr[i]-arr[j]);

         if(fMinDiff>tmp)

        {

             fMinDiff=tmp;

        }

     }

return fMinDiff;

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn