Longest increasing subsequence: Difference between revisions

Longest increasing subsequence in FreeBASIC
(added Pascal example)
(Longest increasing subsequence in FreeBASIC)
Line 1,184:
[0,2,6,9,11,15]
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vb">Sub Lis(arr() As Integer)
Dim As Integer lb = Lbound(arr), ub = Ubound(arr)
Dim As Integer i, lo, hi, mitad, newl, l = 0
Dim As Integer p(ub), m(ub)
For i = lb To ub
lo = 1
hi = l
Do While lo <= hi
mitad = Int((lo+hi)/2)
If arr(m(mitad)) < arr(i) Then
lo = mitad + 1
Else
hi = mitad - 1
End If
Loop
newl = lo
p(i) = m(newl-1)
m(newl) = i
If newL > l Then l = newl
Next i
Dim As Integer res(l)
Dim As Integer k = m(l)
For i = l-1 To 0 Step - 1
res(i) = arr(k)
k = p(k)
Next i
For i = Lbound(res) To Ubound(res)-1
Print res(i); " ";
Next i
End Sub
 
Dim As Integer arrA(5) => {3,2,6,4,5,1}
Lis(arrA())
Print
Dim As Integer arrB(15) => {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}
Lis(arrB())
 
Sleep</syntaxhighlight>
{{out}}
<pre>2 4 5
0 2 6 9 11 15</pre>
 
=={{header|Go}}==
2,122

edits