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
a As String
x As String
b As Integer
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).b <= array(1,min).b Then min = j
If array(1,j).y <= array(1,min).y Then min = j
Next j
Next j
Swap array(min,1).a, array(i,1).a
Swap array(min,1).x, array(i,1).x
Swap array(1,min).b, array(1,i).b
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).a = a(p)
e(p,1).x = a(p)
e(1,p).b = Len(a(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).a & !"\", ";
Print !"\"" & e(p,1).x & !"\", ";
Next
Next
Print Chr(8) & Chr(8) & "]"
Print Chr(8) & Chr(8) & "]"