The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Quicksort in 5 minutes

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jan Lelis

Posts: 136
Nickname: rbjl
Registered: Aug, 2009

Jan Lelis is an IT student from Dresden/Germany
Quicksort in 5 minutes Posted: Sep 15, 2009 6:05 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jan Lelis
Latest Posts From rbJ*_*L.net

Advertisement

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 Array
  def qsort
    return self if self.length <= 1
    pivot = self.shift
    left, right = [],[]
    self.each { |ele| ele <= pivot ? left << ele : right << ele }
    left.qsort + [pivot] + right.qsort
  end
end

# Example of use
# p t[8,6,544,423,3].qsort
CC-BY-NC (DE)

Read: Quicksort in 5 minutes

Topic: Moving from Blogger to Wordpress Previous Topic   Next Topic Topic: Benchmarking Tornado vs. Twisted Web vs. Tornado on Twisted vs. Unicorn

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use