Created
February 26, 2017 05:20
-
-
Save blackknight36/2038d0955eb6d4d23577c81c0aa5b651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| def quicksort(ar) | |
| return ar if ar.length < 2 | |
| left = [] | |
| equal = [] | |
| right = [] | |
| p = ar[0] | |
| ar.each do |i| | |
| left.push(i) if i < p | |
| equal.push(i) if i == p | |
| right.push(i) if i > p | |
| end | |
| sub = quicksort(left) + equal + quicksort(right) | |
| for x in sub | |
| printf("%d ", x) | |
| end | |
| printf("\n") | |
| return sub | |
| end | |
| cnt = gets.chomp.to_i | |
| ar = STDIN.gets.chomp.split(" ").map{|x|x.to_i}; | |
| quicksort(ar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment