Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void vivod(int* arr, int size)
- {
- for (int i{ 0 }; i < size; ++i)
- {
- std::cout << *(arr + i) << " ";
- }
- }
- void sortir(int* arr, int size)
- {
- for (int* ptrh{ arr }; ptrh != (arr + size); ++ptrh)
- {
- for (int* ptrt{ (arr + size) - 1 }; ptrt > ptrh; --ptrt)
- {
- if (*(ptrt) < *(ptrh))
- {
- int tmp = *(ptrt);
- *(ptrt) = *(ptrh);
- *(ptrh) = tmp;
- }
- }
- }
- }
- int main()
- {
- int* ptr{ nullptr };
- int* ptr1{ nullptr };
- int M{ 0 }, N{ 0 };
- // std::cout << "Enter M- ";
- // std::cin >> M;
- // std::cout << "Enter N - ";
- // std::cin >> N;
- ptr = new int[M=15] { 6,1,4,2,8,9,11,26,2,7,8,11,2,2,3 };
- ptr1 = new int[N=15]{ 1,8,29,2,2,9,11,1,2,5,8,34,12,9,8 };
- // for (int i{ 0 }; i < M; ++i)
- // {
- // ptr[i] = rand() % 10;
- // }
- // for (int j{ 0 }; j < N; ++j)
- // {
- // ptr1[j] = rand() % 10;
- // }
- vivod(ptr, M);
- std::cout << "\n";
- vivod(ptr1, N);
- std::cout << "\n";
- sortir(ptr, M);
- vivod(ptr, M);
- std::cout << "\n";
- sortir(ptr1, N);
- vivod(ptr1, N);
- std::cout << "\nSorted\n";
- int* ptrZ = new int[M] {};
- ptrZ[0] = ptr[0];
- int k = 1;
- int size = 1;
- for (int i{ 1 }; i < M; ++i)
- {
- if (ptr[i] != ptr[i - 1])
- {
- ptrZ[k] = ptr[i];
- ++k; ++size;
- }
- }
- vivod(ptrZ, M);
- std::cout << "Uniqued A\n";
- std::cout << "\n";
- std::cout << " size = " << size << "\n";
- int* ptr1z = new int[N] {};
- ptr1z[0] = ptr1[0];
- int t = 1;
- int size1 = 1;
- for (int i{ 1 }; i < N; ++i)
- {
- if (ptr1[i] != ptr1[i - 1])
- {
- ptr1z[t] = ptr1[i];
- ++t; ++size1;
- }
- }
- vivod(ptr1z, N);
- std::cout << "Uniqued B\n";
- std::cout << "\n";
- std::cout << "size1 = =" << size1;
- std::cout << "\n";
- delete[]ptr;
- delete[]ptr1;
- int* ptrCopy = new int [size] {};
- for (int i{ 0 }; i < size; ++i)
- {
- ptrCopy[i] = ptrZ[i];
- }
- vivod(ptrCopy, size);
- std::cout << "Cut tail A\n";
- std::cout << "\n";
- //delete[]ptr1z;
- int* konec = new int[M] {};
- auto elB{ptr1z};
- auto bEnd{ptr1z + N};
- auto elRes{konec};
- bool found {false};
- for ( auto elA{ptrCopy}, aEnd {ptrCopy + size}; elA < aEnd; ++elA)
- {
- for(elB = ptr1z,found = false; elB < bEnd; ++elB)
- {
- if (*elA == *elB) {found = true; break;}
- }
- if(!found){ *elRes++ = *elA;}
- }
- // int c = 0;
- // int y{0};
- // for (int i{ 0 }; i < M; ++i)
- // {
- // for (y=0; y < size1; ++y)
- // {
- // if (ptr1z[i] == ptrCopy[y])
- // {
- // continue;
- // }
- // if (ptr1z[i] != ptrCopy[y])
- // {
- // // konec[c] = ptrZ[i];
- //
- // }
- // }
- // konec[c] = ptrCopy[y];
- // ++c;
- // }
- vivod(konec, M);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement