Advertisement
avr39-ripe

gozdaAdiffBPtrFix

Mar 31st, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include <iostream>
  2. void vivod(int* arr, int size)
  3. {
  4.     for (int i{ 0 }; i < size; ++i)
  5.     {
  6.         std::cout << *(arr + i) << " ";
  7.     }
  8. }
  9. void sortir(int* arr, int size)
  10. {
  11.     for (int* ptrh{ arr }; ptrh != (arr + size); ++ptrh)
  12.     {
  13.         for (int* ptrt{ (arr + size) - 1 }; ptrt > ptrh; --ptrt)
  14.         {
  15.             if (*(ptrt) < *(ptrh))
  16.             {
  17.                 int tmp = *(ptrt);
  18.                 *(ptrt) = *(ptrh);
  19.                 *(ptrh) = tmp;
  20.             }
  21.         }
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     int* ptr{ nullptr };
  28.     int* ptr1{ nullptr };
  29.     int M{ 0 }, N{ 0 };
  30. //    std::cout << "Enter M- ";
  31. //    std::cin >> M;
  32. //    std::cout << "Enter N - ";
  33. //    std::cin >> N;
  34.  
  35.     ptr = new int[M=15] { 6,1,4,2,8,9,11,26,2,7,8,11,2,2,3 };
  36.     ptr1 = new int[N=15]{ 1,8,29,2,2,9,11,1,2,5,8,34,12,9,8 };
  37. //    for (int i{ 0 }; i < M; ++i)
  38. //    {
  39. //        ptr[i] = rand() % 10;
  40. //    }
  41. //    for (int j{ 0 }; j < N; ++j)
  42. //    {
  43. //        ptr1[j] = rand() % 10;
  44. //    }
  45.     vivod(ptr, M);
  46.     std::cout << "\n";
  47.     vivod(ptr1, N);
  48.     std::cout << "\n";
  49.     sortir(ptr, M);
  50.     vivod(ptr, M);
  51.     std::cout << "\n";
  52.     sortir(ptr1, N);
  53.     vivod(ptr1, N);
  54.     std::cout << "\nSorted\n";
  55.     int* ptrZ = new int[M] {};
  56.     ptrZ[0] = ptr[0];
  57.     int k = 1;
  58.     int size = 1;
  59.     for (int i{ 1 }; i < M; ++i)
  60.     {
  61.         if (ptr[i] != ptr[i - 1])
  62.         {
  63.             ptrZ[k] = ptr[i];
  64.             ++k; ++size;
  65.         }
  66.     }
  67.     vivod(ptrZ, M);
  68.     std::cout << "Uniqued A\n";
  69.     std::cout << "\n";
  70.     std::cout << " size = " << size << "\n";
  71.     int* ptr1z = new int[N] {};
  72.     ptr1z[0] = ptr1[0];
  73.     int t = 1;
  74.     int size1 = 1;
  75.     for (int i{ 1 }; i < N; ++i)
  76.     {
  77.         if (ptr1[i] != ptr1[i - 1])
  78.         {
  79.             ptr1z[t] = ptr1[i];
  80.             ++t; ++size1;
  81.         }
  82.     }
  83.     vivod(ptr1z, N);
  84.     std::cout << "Uniqued B\n";
  85.     std::cout << "\n";
  86.     std::cout << "size1 = =" << size1;
  87.     std::cout << "\n";
  88.     delete[]ptr;
  89.     delete[]ptr1;
  90.     int* ptrCopy = new int [size] {};
  91.     for (int i{ 0 }; i < size; ++i)
  92.     {
  93.  
  94.         ptrCopy[i] = ptrZ[i];
  95.     }
  96.     vivod(ptrCopy, size);
  97.     std::cout << "Cut tail A\n";
  98.     std::cout << "\n";
  99.     //delete[]ptr1z;
  100.     int* konec = new int[M] {};
  101.  
  102.     auto elB{ptr1z};
  103.     auto bEnd{ptr1z + N};
  104.     auto elRes{konec};
  105.     bool found {false};
  106.     for ( auto elA{ptrCopy}, aEnd {ptrCopy + size}; elA < aEnd; ++elA)
  107.     {
  108.         for(elB = ptr1z,found = false; elB < bEnd; ++elB)
  109.         {
  110.             if (*elA == *elB) {found = true; break;}
  111.         }
  112.         if(!found){ *elRes++ = *elA;}
  113.     }
  114.  
  115. //    int c = 0;
  116. //    int y{0};
  117. //    for (int i{ 0 }; i < M; ++i)
  118. //    {
  119. //        for (y=0; y < size1; ++y)
  120. //        {
  121. //            if (ptr1z[i] == ptrCopy[y])
  122. //            {
  123. //                continue;
  124. //            }
  125. //            if (ptr1z[i] != ptrCopy[y])
  126. //            {
  127. //               // konec[c] = ptrZ[i];
  128. //
  129. //            }
  130. //        }
  131. //        konec[c] = ptrCopy[y];
  132. //                        ++c;
  133. //    }
  134.     vivod(konec, M);
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement