Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  חזרה על רקורסיות
  4. //
  5. //  Created by Daniel Gelfand on 21/02/2020.
  6. //  Copyright © 2020 Daniel Gelfand. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. void swap(char *v,char *u);
  11.  
  12. void samenubmerz(int* Arr,int n,int* Brr, int m);
  13. int main()
  14. {
  15.     int Arr[12] = {2,2,3,3,3,4,4,5,5,5,6,6};
  16.     int Brr[9] = {7,5,2,5,8,4,1,2,9};
  17.     samenubmerz(Arr, 12, Brr, 9);
  18.  
  19.    
  20. }
  21. void samenubmerz(int* Arr,int n,int* Brr, int m)
  22. {
  23.    
  24.     int i;
  25.     int low,high,mid;
  26.     low=0;
  27.     high = n-1;
  28.     for (i=0; i<m; i++)
  29.     {
  30.         low=0;
  31.         high = n-1;
  32.         while(low <= high)
  33.         {
  34.             mid = (low+high) / 2;
  35.             if(Brr[i] == Arr[mid])
  36.             {
  37.                 printf("%d\n",Brr[i]);
  38.             }
  39.             if(Arr[mid] > Brr[i])
  40.             {
  41.                 low = mid+1;
  42.             }
  43.             else
  44.                 high = mid-1;
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50.  
  51. void swap(char *v,char *u)
  52. {
  53.     char temp;
  54.     temp=*v;
  55.     *v=*u;
  56.     *u=temp;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement