Common sorted list: Difference between revisions

m (→‎{{header|Wren}}: Minor tidy)
 
(4 intermediate revisions by 3 users not shown)
Line 637:
{ 1 3 4 5 7 8 9 }
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Dim As Integer nums(2, 7) = {{5,1,3,8,9,4,8,7},{3,5,9,8,4},{1,3,7,9}}
Dim Shared As Integer sumNums()
 
Sub Sum(arr() As Integer, vals As Integer)
Redim Preserve arr(Ubound(arr) + 1)
arr(Ubound(arr)) = vals
End Sub
 
Sub Del(arr() As Integer, index As Integer)
For i As Integer = index To Ubound(arr) - 1
arr(i) = arr(i + 1)
Next i
Redim Preserve arr(Ubound(arr) - 1)
End Sub
 
Sub showArray(arr() As Integer)
Dim As String txt = ""
Print "[";
For n As Integer = 1 To Ubound(arr)
txt &= Str(arr(n)) & ","
Next n
txt = Left(txt, Len(txt) - 1)
txt &= "]"
Print txt
End Sub
 
Sub Sort(arr() As Integer)
Dim As Integer i, j
For i = 0 To Ubound(arr) - 1
For j = i + 1 To Ubound(arr)
If arr(i) > arr(j) Then Swap arr(i), arr(j)
Next j
Next i
End Sub
 
For n As Integer = 0 To Ubound(nums, 1)
For m As Integer = 0 To Ubound(nums, 2)
Sum(sumNums(), nums(n, m))
Next m
Next n
 
Sort(sumNums())
For n As Integer = Ubound(sumNums) To 1 Step -1
If sumNums(n) = sumNums(n - 1) Then
Del(sumNums(), n)
End If
Next n
 
Sort(sumNums())
 
Print "common sorted list elements are: ";
showArray(sumNums())
 
Sleep</syntaxhighlight>
{{out}}
<pre>common sorted list elements are: [1,3,4,5,7,8,9]</pre>
 
=={{header|Go}}==
Line 815 ⟶ 873:
{{out}}
<pre>@[1, 3, 4, 5, 7, 8, 9]</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Program CommonSortedList;
{$mode ObjFPC}{$H+}
 
Uses sysutils,fgl;
 
Type
tarr = array Of array Of integer;
 
Const List1: tarr = ((5,1,3,8,9,4,8,7), (3,5,9,8,4), (1,3,7,9));
 
Var list : specialize TFPGList<integer>;
 
Procedure addtolist(arr : tarr);
Var i : integer;
arr2 : array Of integer;
Begin
For arr2 In arr Do
For i In arr2 Do
If (list.indexof(i) = -1) {make sure number isn't in list already}
Then list.add(i);
End;
 
Function CompareInt(Const Item1,Item2: Integer): Integer;
Begin
result := item1 - item2;
End;
 
Var i : integer;
Begin
list := specialize TFPGList<integer>.create;
addtolist(list1);
List.Sort(@CompareInt); {quick sort the list}
For i In list Do
write(i:4);
list.destroy;
End.
</syntaxhighlight>
{{out}}
<pre>
1 3 4 5 7 8 9
</pre>
 
=={{header|Perl}}==
Line 993 ⟶ 1,096:
{{out}}
<pre>[1, 3, 4, 5, 7, 8, 9]
</pre>
 
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
F ← ⊏⍏.◴/◇⊂
</syntaxhighlight>
{{out}}
<pre>
F {[5 1 3 8 9 4 8 7] [3 5 9 8 4] [1 3 7 9]}
[1 3 4 5 7 8 9]
</pre>
 
44

edits