Home > Database > Mysql Tutorial > 2.11 最近点对

2.11 最近点对

WBOY
Release: 2016-06-07 15:43:15
Original
1203 people have browsed it

一维数组总共包含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;

}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template