I want to ask : exist a way to stop (interrupt) a sorting process through std::sort given a comparation function ? Inside comparation function exist heavy calculations, but also it can happen that a absolute result of comparation (<) is not possible, in which case i want to interrupt this sorting process in order to start another type of sorting process.
Only it is possible using "trow" and "catch" or exist another way ?
You mean, compare every element with every element ?
My god, i told you this is expensive in termes of time.
My another idea of course, is to create a sorting algorithm or copy std::sort's code, and change it, with this extra, but my question is if or not exist a way to interrupt this process, with some kind of condition ?
It will give up to have a order-result, in will conform to only contain groups : which elements are same (equivalents) , and which elements are different (non equivalents). This algorithm not will give results which are so precise as another ordering by <, because we only can sort this elements (which are agrouped by != and ==) by number of elements by group, which not is in all cases satisfactory.
So, i will first try to obtain a order off this elements, and if this fails, use results af agroupments.
greatings, and thanks
> a way to stop (interrupt) a sorting process through std::sort given a comparation function ?
> Only it is possible using "trow" and "catch" or exist another way ?
There is no way to interrupt std::sort mid-way and then later resume the sort from where it was interrupted.
std::sort can be aborted by throwing an exception from the comparison predicate; however the sequence would be in some unspecified order after that.
4 21 1 2 3 4 5 6 9 10
Process returned 0 (0x0) execution time : 0.719 s
Press any key to continue.
edit: OP: just seen JLBorges' and I want to stress once again what I have said before and s/he is saying as well, the container will be left in an unspecified state
Thanks for both.
What JLBorges said have sense.
gunnerfunner thanks, but you code contains errors and also not help me.
You also forget to return a value in case
abs(lhs-rhs)>=10