Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Icon > Re: About quick...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 171 of 189
Post > Topic >>

Re: About quicksort procedure in icon

by Steve Wampler <sbw@[EMAIL PROTECTED] > Dec 21, 2007 at 02:23 PM

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
->
 




 2 Posts in Topic:
About quicksort procedure in icon
jopogar@[EMAIL PROTECTED]  2007-12-20 13:10:34 
Re: About quicksort procedure in icon
Steve Wampler <sbw@[EM  2007-12-21 14:23:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 18 20:39:50 CDT 2008.