This post originated from an RSS feed registered with Ruby Buzz
by Jan Lelis.
Original Post: Quicksort in 5 minutes
Feed Title: rbJ*_*L.net
Feed URL: http://feeds.feedburner.com/rbJL
Feed Description: Hi, I am a fan of Ruby and like to explore it and the world around ;).
So I started this blog, where I am publishing code snippets, tutorials for beginners as well as general thoughts about Ruby, the web or programming in general.
Some time ago, I conducted a short presentation about Ruby. And to impress the audience, I did some live coding and implemented the quicksort algorithm in 5 minutes. They were impressed :)\n
class Arraydef qsortreturnselfifself.length<=1pivot=self.shiftleft,right=[],[]self.each{|ele|ele<=pivot?left<<ele:right<<ele}left.qsort+[pivot]+right.qsortendend# Example of use# p t[8,6,544,423,3].qsort