Advertisement
_takumi

test_array

Feb 9th, 2022
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. static void test(ll *a, ll *sorted, int n) {
  2.     ll *checked = (ll *) calloc(n, sizeof(ll));
  3.     int found = 0;
  4.     for (int i = 0; i < n; ++i) {
  5.         for (int j = 0; j < n; ++j) {
  6.             if (sorted[i] == a[j]) {
  7.                 if (checked[j] == 0) {
  8.                     checked[j] = 1;
  9.                     found = 1;
  10.                     break;
  11.                 }
  12.             }
  13.         }
  14.         if (found == 0)
  15.             printf("Элементы отсортированного массива не совпадают с элементами изначального массива");
  16.         else
  17.             found = 0;
  18.     }
  19.     for (int i = 1; i < n; ++i) {
  20.         if (sorted[i] < sorted[i - 1]) {
  21.             printf("Элементы отсортированы в неправильном порядке\n");
  22.         }
  23.     }
  24.     for (int i = 0; i < n; ++i) {
  25.         if (!checked[i])
  26.             printf("Элементы отсортированного массива не совпадают с элементами изначального массива");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement