1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

スリープソートをRubyで汎用的に書いてみる。

Last updated at Posted at 2012-03-16

参考: http://niku.name/20110520.html


class Array
    def sleep_sort(&block)
	result = Array.new
	self.map {|n|
	    Thread.start {
		sleep n.to_i
		yield n if block_given?
		result << n
	    }
	}.each(&:join)
	result
    end
end

ARGV.sleep_sort {|n| puts "*#{n}*" }

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?