Largest int from concatenated ints: Difference between revisions
replace incorrect FreeBASIC solution with a correct one
(Add min) |
(replace incorrect FreeBASIC solution with a correct one) |
||
Line 688:
=={{header|FreeBASIC}}==
<lang freebasic>
function catint( a as string, b as string ) as uinteger
return valint(a+b)
end function
function grt( a as string, b as string ) as boolean
return catint(a, b)>catint(b, a)
end function
sub shellsort( a() as string )
'quick and dirty shellsort, not the focus of this exercise
dim as uinteger gap = ubound(a), i, j, n=ubound(a)
dim as string temp
do
gap = int(gap / 2.2)
for i=gap to n
temp = a(i)
j=i
while j>=gap andalso grt( a(j-gap), temp )
a(j) = a(j - gap)
j -= gap
wend
a(j) = temp
next i
loop until gap = 1
end sub
sub sort_and_print( a() as string )
shellsort(a())
for i=0 to ubound(a)
outstring = a(i)+outstring
next i
print outstring
end sub
dim as string set1(8) = {"1", "34", "3", "98", "9", "76", "45", "4"}
dim as string set2(4) = {"54", "546", "548", "60"}
sort_and_print(set1())
sort_and_print(set2())</lang>
{{out}}
<pre>998764543431
6054854654
</pre>
=={{header|Gambas}}==
|