At the request of a potential employer, I have been giving myself a crash course in the programming language S (the most common variants of which are named S+ and R, just to confuse people). I am an old C programmer, mainly, and this language is much higher level than that. Plus it is object oriented and more more function based than what I am used to. Still, this is quite impressive, and very easy to code.
qsort=function(a) if (length(a)<=1) a else c(qsort(a[a<a[1]]),a[1],qsort(a[a>a[1]]))
That's right, one line. Works for an array of any data type for which the logical comparison a<b makes sense, too.
No comments:
Post a Comment