Order two numerical lists: Difference between revisions
Content added Content deleted
(category sorting) |
|||
Line 15: | Line 15: | ||
return L1.MaxIndex() < L2.MaxIndex() |
return L1.MaxIndex() < L2.MaxIndex() |
||
}</lang> |
}</lang> |
||
=={{header|C}}== |
|||
<lang c>int list_cmp(int *a, int la, int *b, int lb) |
|||
{ |
|||
int i, l = la; |
|||
if (l > lb) l = lb; |
|||
for (i = 0; i < l; i++) { |
|||
if (a[i] == b[i]) continue; |
|||
return (a[i] > b[i]) ? 1 : -1; |
|||
} |
|||
if (la == lb) return 0; |
|||
return la > lb ? 1 : -1; |
|||
}</lang> |
|||
This funciton returns one of three states, not a boolean. One can define boolean comparisons, such as <code>list_less_or_eq</code>, based on it:<lang c>#define list_less_or_eq(a,b,c,d) (list_cmp(a,b,c,d) != 1)</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |