From bb46f062dca3b35b0a2c66019ce5020b2bfdabce Mon Sep 17 00:00:00 2001 From: Ayush Nagar <32647423+ayushnagar123@users.noreply.github.com> Date: Tue, 2 Oct 2018 12:00:43 +0530 Subject: [PATCH] median search=> --- Search/interpolition.cpp | 251 +++++++++++++++++++++++++++++++++++++++ Search/median_search.cpp | 72 +++++++++++ 2 files changed, 323 insertions(+) create mode 100644 Search/interpolition.cpp create mode 100644 Search/median_search.cpp diff --git a/Search/interpolition.cpp b/Search/interpolition.cpp new file mode 100644 index 000000000..de0cc8faa --- /dev/null +++ b/Search/interpolition.cpp @@ -0,0 +1,251 @@ +#include +#include +#include +#include +using namespace std; +class interpolition +{ + public: + int i,j=0,j1=0,j2=0,j3=0; + vectora; + vectora1; + vectora2; + vectora3; + void input(int n) + { + a[j]=n;j++; + } + void input(double n) + { + a1.push_back(n); + } + void input(char n) + { + a2.push_back(n); + } + void input(string n) + { + a3.push_back(n); + } + void sorting() + { + if(a.size()!=0) + {sort(a.begin(),a.end()); + } + if(a1.size()!=0) + {sort(a1.begin(),a1.end()); + } + if(a2.size()!=0) + {sort(a2.begin(),a2.end()); + } + if(a3.size()!=0) + {sort(a3.begin(),a3.end()); + } + } + int binary(int x) + { + int s=0,l=a.size(),c=0,mid; + do + { + c=0; + mid=(l-s/(a[l]-a[s]))*(x-a[s]); + if(a[mid]==x) + { + return mid; + } + if(a[mid]>x) + { + l=mid-1; + } + if(a[mid]x) + { + l=mid-1; + } + if(a1[mid]x) + { + l=mid-1; + } + if(a2[mid] st1) + { + hi=pos-1; + } + else + { + low=pos+1; + } + } + return -1; + } +}; +int main() +{ + interpolition b; + int ch; + cout<<"what is the datatype of input:-\n1. int\n2. double\n3. char\n4. string"<>ch; + switch(ch) + { + case 1: + { + int n,m; + do + { + cout<<"enter the value to be inserted in array:-"; + cin>>n; + b.input(n); + cout<<"do you want to add more elements? 1. yes 2. no\n"; + cin>>m; + }while(m!=0); + b.sorting(); + int x; + cout<<"enter the value to be searched in array:-"; + cin>>x; + int k=b.binary(x); + if(k==-1) + { + cout<>n; + b.input(n); + cout<<"do you want to add more elements? 1. yes 2. no\n"; + cin>>m; + }while(m!=0); + b.sorting(); + double x; + cout<<"enter the value to be searched in array:-"; + cin>>x; + int k=b.binary(x); + if(k==-1) + { + cout<>n; + b.input(n); + cout<<"do you want to add more elements? 1. yes 2. no\n"; + cin>>m; + }while(m!=0); + b.sorting(); + char x; + cout<<"enter the value to be searched in array:-"; + cin>>x; + int k=b.binary(x); + if(k==-1) + { + cout<>n; + b.input(n); + cout<<"do you want to add more elements? 1. yes 2. no\n"; + cin>>m; + }while(m!=0); + b.sorting(); + string x; + cout<<"enter the value to be searched in array:-"; + cin>>x; + int k=b.binary(x); + if(k==-1) + { + cout< +#include +#include +#include +#include +#include +#include +using namespace std; +vectorv; +vectors1; +vectors2; +vectors3; +template +void comp(X x) +{ + if(s1.size()>=x && s1.size()+s2.size()x) + { + sort(s1.begin(),s1.end()); + cout<x) + { + sort(s3.begin(),s3.end()); + cout<>x; + comp(x-1); + return 0; +}