W
Since this was posted to the C++ section of the forum, I suggest std::sort + exceptions (the topic has been moved to C, so my answer is not really useful any more, but maybe still fun to play with)
#include <algorithm>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <vector>
#include <stdexcept>
using namespace std;
bool compare(int a, int b) {
fmt::println("{} <=> {}?", a, b);
if (a == b) throw runtime_error("Equal numbers compared");
return a < b;
}
int main() {
vector<int> a {1,5,3,5,6,2};
try {
sort(a.begin(), a.end(), compare);
} catch (const runtime_error &e) {
fmt::println("Stopped sorting: {}!", e.what());
}
fmt::print("A: {}!", a);
}