Liste des Groupes | Revenir à cl c |
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:It's allowed to crash because it runs out of stack space if the sort function isb't consistent. I see your point. If we pass it a triplet with an entry between my_icon_L and my_icon_D, like my_icon_H, it will get into trouble. And of course I forgot because for our specific application you don't get names like that.
On 20/06/2024 08:55, David Brown wrote:...Unless I'm missing something here, that code does not do what you sayYou've made it clear you know nothing about the language. Fair enough -Yes but I just don't.
we all know almost nothing about almost all programming languages. But
trust someone who does.
>
Everyone says "oh yes, that is easy - goto a Python group" and so
on. No-one actually comes up with the code.
>
In C, what we do is write a special version of strcmp
>
int strcmp_light_and_dark(const char *a, const char *b)
{
int i;
>
for (i = 0; a[i] && b[i]; i++)
{
if (a[i] != b[i])
{
if (a[i] == 'L' && b[i] == 'D' && i > 0 && a[i-1] == '_')
return -1;
if (a[i] == 'D' && b[i] == 'L' && i > 0 && a[i-1] = '_')
return 1;
break;
}
}
>
return a[i] - b[i];
>
}
>
So easy to do.
you want. You gave an example of some input and the desired output but
this comparison function does not sort into the ordering you gave.
You may find this "ordering" hard to duplicate in other languages
because it is not even an ordering in the mathematical sense as it is
not transitive.
Can you specify the desired ordering as a total or partial order
relation?
On a C language point, I don't think the standard says anything about
sorting with non-order functions like the one above. Is an
implementation of qsort permitted to misbehave (for example by not
terminating) when the comparison function does not implement a proper
order relation?
Les messages affichés proviennent d'usenet.