Sajib_Ahmed

marge and sort and search

Mar 4th, 2021
632
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,p,k;
  6.     cout<<"Enter Arry one size\n";
  7.     cin>>n;
  8.     int a[n],i;
  9.     cout<<"Enter Arry one value\n";
  10.     for(i=0; i<n; i++)
  11.     {
  12.         cin>>a[i];
  13.  
  14.     }
  15.     cout<<"Enter Arry Two size :\n";
  16.     cin>>p;
  17.     int b[p],j,m,r;
  18.     cout<<"Enter Arry Two value :\n";
  19.     for(j=0; j<p; j++)
  20.     {
  21.         cin>>b[j];
  22.     }
  23.     int t=n+p;
  24.     int final[t];
  25.     for(i=0;i<n;i++)
  26.     {
  27.         final[i]=a[i];
  28.     }
  29.     k=i;
  30.     for(j=0;j<p;j++)
  31.     {
  32.         final[k]=b[j];
  33.         k++;
  34.     }
  35.     cout<<"Final value :\n";
  36.  
  37.     for(i=1; i<t; i++)
  38.     {
  39.         m=final[i];
  40.         r=i-1;
  41.         while(r>=0&&final[r]<m)
  42.         {
  43.             final[r+1]=final[r];
  44.             r--;
  45.         }
  46.         final[r+1]=m;
  47.     }
  48.     for(i=0; i<t; i++)
  49.     {
  50.         cout<<final[i]<<"   ";
  51.     }
  52.     cout<<"\n";
  53.     int high=t-1;
  54.  
  55.     int low=0,s,res=0;
  56.     cout<<"Enter search value\n ";
  57.     cin>>s;
  58.  
  59.     while(low<=high)
  60.     {
  61.         int mid = (low + high) / 2;
  62.  
  63.         if (final[mid] == s)
  64.         {
  65.  
  66.             int q=count(final, final + t, s);
  67.             cout<<s<<" is found "<<q<<" times in the array";
  68.             return 0;
  69.  
  70.         }
  71.  
  72.         if (final[mid]<s)
  73.         {
  74.             high = mid - 1;
  75.         }
  76.         else
  77.         {
  78.             low= mid + 1;
  79.         }
  80.         final[mid]=0;
  81.         sort(final,final+t,greater<int>());
  82.     }
  83.  
  84.     cout<<"\nNot Found\n";
  85.  
  86. }
  87.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×