Advertisement
193030

DR5 02. WIP

Nov 21st, 2021
45
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. unsigned size(int A[], unsigned n)
  6. {
  7. return (n*sizeof(int)*8);
  8. }
  9. void remove( int A[], int n, int k )
  10. {
  11. A[k/32] &= ~(1 << (k%32));
  12. }
  13.  
  14. void add( int A[], int n, int k )
  15. {
  16. A[k/32] |= 1 << (k%32); // Set the bit at the k-th position in A[i]
  17. }
  18.  
  19.  
  20. void Union(int a[], int b[], int c[], int n)
  21. {
  22. for(int i =0; i<n; i++)
  23. {
  24. c[i]= a[i]|b[i];
  25. }
  26.  
  27. }
  28.  
  29. void subtract(int a[], int b[], int c[], int n)
  30. {
  31. for(int i =0; i<n; i++)
  32. {
  33. c[i]= a[i]^b[i];
  34. }
  35.  
  36. }
  37. int main()
  38. {
  39. int A[3] = {0};
  40. int n = sizeof(A)/sizeof(A[0]);
  41. add(A,n,32);
  42. //remove(A,n,32);
  43. cout << A[1] << " size: " << size(A,n);
  44. int a[] = {10,20,30};
  45. int b[] = {10,22,30};
  46. int c[3] = {0};
  47. int c2[3] = {0};
  48.  
  49. Union(a,b,c,3);
  50. subtract(a,b,c2,3);
  51. cout << endl;
  52. for(int i =0; i<3; i++)
  53. cout << c[i];
  54.  
  55. cout << endl;
  56. for(int i =0; i<3; i++)
  57. cout << c2[i];
  58.  
  59. }
  60. // Trqbva da se editne za C, i da se premeinuvat funkcii i parametri
  61.  
Advertisement
RAW Paste Data Copied
Advertisement