Decorate-sort-undecorate idiom: Difference between revisions
Content added Content deleted
(Added FreeBasic) |
|||
Line 156: | Line 156: | ||
FreeBASIC doesn't normally print string lists in "quoted" form though I've added the quotes here to be consistent with the other solutions. |
FreeBASIC doesn't normally print string lists in "quoted" form though I've added the quotes here to be consistent with the other solutions. |
||
<syntaxhighlight lang="vb">Type map |
<syntaxhighlight lang="vb">Type map |
||
x As String |
|||
y As Integer |
|||
End Type |
End Type |
||
Line 166: | Line 166: | ||
min = i |
min = i |
||
For j = i + 1 To ub |
For j = i + 1 To ub |
||
If array(1,j). |
If array(1,j).y <= array(1,min).y Then min = j |
||
Next j |
Next j |
||
Swap array(min,1). |
Swap array(min,1).x, array(i,1).x |
||
Swap array(1,min). |
Swap array(1,min).y, array(1,i).y |
||
Next i |
Next i |
||
End Sub |
End Sub |
||
Line 179: | Line 179: | ||
' Decorate |
' Decorate |
||
For p = lb To ub |
For p = lb To ub |
||
e(p,1). |
e(p,1).x = a(p) |
||
e(1,p). |
e(1,p).y = Len(a(p)) |
||
Next |
Next |
||
Line 189: | Line 189: | ||
Print "["; |
Print "["; |
||
For p = lb To ub |
For p = lb To ub |
||
Print !"\"" & e(p,1). |
Print !"\"" & e(p,1).x & !"\", "; |
||
Next |
Next |
||
Print Chr(8) & Chr(8) & "]" |
Print Chr(8) & Chr(8) & "]" |