Skip to content

Commit

Permalink
Lab: core_bound/function_inlining_1
Browse files Browse the repository at this point in the history
  • Loading branch information
stankevichevg committed Nov 25, 2024
1 parent 9043f41 commit 4e436ff
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions labs/core_bound/function_inlining_1/solution.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@

#include "solution.h"
#include <algorithm>
#include <stdlib.h>

static int compare(const void *lhs, const void *rhs) {
auto &a = *reinterpret_cast<const S *>(lhs);
auto &b = *reinterpret_cast<const S *>(rhs);

if (a.key1 < b.key1)
return -1;

if (a.key1 > b.key1)
return 1;

if (a.key2 < b.key2)
return -1;

if (a.key2 > b.key2)
return 1;

return 0;
}

void solution(std::array<S, N> &arr) {
qsort(arr.data(), arr.size(), sizeof(S), compare);
std::sort(arr.begin(), arr.end(), [](const S& a, const S& b) {
return a.key1 < b.key1 || (a.key1 == b.key1) && (a.key2 < b.key2);
});
}

0 comments on commit 4e436ff

Please sign in to comment.