jopogar@[EMAIL PROTECTED]
wrote:
> Hello!! I'm starting with Unicon and I'm trying to use
> qsort procedure. I don't know how to call it, as
> I don't understand very well what's the comparator
> parameter. An example of calling the procedure could
> be great.
This question really belongs on the unicon group mailing
list since qsort.icn isn't readily usable under standard
Icon (it can be used, but you don't want to know how!).
You can visit http://unicon.org/
to see how to sign up
for the unicon-general mailing list if you're interested.
Nevertheless, here's a example (with the correct syntax
for the comparator class) showing how qsort can be used.
Note that lists of much more complicated items can can
be sorted by specifying an appropriate comparator. This
example can be used to sort numeric or string lists
from largest to smallest.
------------------------------------------------
->cat qsorttest.icn
link "qsort"
procedure main()
every write(!util::qsort([3,1,4,1,5,9,2,6,3], Compare()))
end
# This comparator can be used to order values from largest to smallest.
class Compare()
# Succeed only if the first argument is greater than the second
method compare(l,r)
return l > r
end
end
->unicon qsorttest.icn
Parsing qsorttest.icn: ...
/opt/bin/icont -c -O qsorttest.icn /tmp/uni17069871
Translating:
qsorttest.icn:
main
Compare_compare
Compare
Compareinitialize
No errors
/opt/bin/icont qsorttest.u
Linking:
->qsorttest
9
6
5
4
3
3
2
1
1
->


|