diff --git a/code/closestpairofpoints.cpp b/code/closestpairofpoints.cpp new file mode 100644 index 0000000..ed5f2de --- /dev/null +++ b/code/closestpairofpoints.cpp @@ -0,0 +1,188 @@ +#include +#include +#include +#include +#include +using namespace std; +float xfirstx; +float yfirsty; +float xsecondx; +float ysecondy; +class mymath{ +public: + float mysqrt(const float x){ + const double prec=0.00001; + float low,high,anstry; + if (x < 1){ + low = x; + high = 1; + } + else{ + low = 1; + high = x; + } + while ((high-low) > prec){ + anstry = (low+high)/2; + if(anstry*anstry>x) + high=anstry; + else + low=anstry; + } + return (low + high)/2; + } +}; +class points{ + float x; + float y; +public: + float showx(){ + return x; + } + float showy(){ + return y; + } + void setx(float in){ + x=in; + } + void sety(float in){ + y=in; + } + int xpartition(points arr[],int p,int q){ + int k=p; + for(int i=p+1;i<=q;i++){ + if(arr[i].showx()>n; +points input[n],xsorted[n],ysorted[n]; +// srand(time(NULL)); +for(int i=0;i