Order two numerical lists: Difference between revisions

Added an implementation in C#.
m (→‎{{header|Perl 6}}: flatten before assignment)
(Added an implementation in C#.)
Line 182:
}</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 sharp|C#}}==
<lang csharp>namespace RosettaCode.OrderTwoNumericalLists
{
using System;
using System.Collections.Generic;
 
internal static class Program
{
private static bool IsLessThan(this IEnumerable<int> enumerable,
IEnumerable<int> otherEnumerable)
{
using (
IEnumerator<int> enumerator = enumerable.GetEnumerator(),
otherEnumerator = otherEnumerable.GetEnumerator())
{
while (true)
{
if (!otherEnumerator.MoveNext())
{
return false;
}
 
if (!enumerator.MoveNext())
{
return true;
}
 
if (enumerator.Current == otherEnumerator.Current)
{
continue;
}
 
return enumerator.Current < otherEnumerator.Current;
}
}
}
 
private static void Main()
{
Console.WriteLine(
new[] {1, 2, 1, 3, 2}.IsLessThan(new[] {1, 2, 0, 4, 4, 0, 0, 0}));
}
}
}</lang>
{{out}}
<pre>False</pre>
 
=={{header|C++}}==
Anonymous user