Order two numerical lists: Difference between revisions

Content added Content deleted
(Added Ada)
Line 5: Line 5:


The order is determined by [[wp:Lexicographical order#Ordering of sequences of various lengths|lexicographic order]]: Comparing the first element of each list. If the first elements are equal, then the second elements should be compared, and so on, until one of the list has no more elements. If the first list runs out of elements the result is <code>true</code>. if the second list or both run out of elements the result is <code>false</code>.
The order is determined by [[wp:Lexicographical order#Ordering of sequences of various lengths|lexicographic order]]: Comparing the first element of each list. If the first elements are equal, then the second elements should be compared, and so on, until one of the list has no more elements. If the first list runs out of elements the result is <code>true</code>. if the second list or both run out of elements the result is <code>false</code>.

=={{header|Ada}}==
This is already implemented in the built-in comparison operators for arrays of types that have a direct ordering.
This also includes arrays of user defined types, using the type definition order from smallest to largest.
Demonstrated in the program below:
<lang Ada>
with Ada.Text_IO; use Ada.Text_IO;
procedure Order is

type IntArray is array (Positive range <>) of Integer;
List1 : IntArray := (1, 2, 3, 4, 5);
List2 : IntArray := (1, 2, 1, 5, 2, 2);
List3 : IntArray := (1, 2, 1, 5, 2);
List4 : IntArray := (1, 2, 1, 5, 2);

type Animal is (Rat, Cat, Elephant);
type AnimalArray is array (Positive range <>) of Animal;
List5 : AnimalArray := (Cat, Elephant, Rat, Cat);
List6 : AnimalArray := (Cat, Elephant, Rat);
List7 : AnimalArray := (Cat, Cat, Elephant);

begin
Put_Line (Boolean'Image (List1 > List2)); -- True
Put_Line (Boolean'Image (List2 > List3)); -- True
Put_Line (Boolean'Image (List3 > List4)); -- False, equal
Put_Line (Boolean'Image (List5 > List6)); -- True
Put_Line (Boolean'Image (List6 > List7)); -- True
end Order;
</lang>
Output:
<pre>
TRUE
TRUE
FALSE
TRUE
TRUE
</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
{{works with|AutoHotkey_L}}