Created
January 26, 2013 01:48
-
-
Save amano41/4639572 to your computer and use it in GitHub Desktop.
Python の練習でクイックソートを書いてみました。
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
import random | |
def qsort(ls): | |
if len(ls) <= 1: return ls | |
p = ls[0] | |
return qsort([x for x in ls if x < p]) + \ | |
[p] + \ | |
qsort([x for x in ls if x > p]) | |
if __name__ == "__main__": | |
data = range(10) | |
random.shuffle(data) | |
print "orig = %s" % data | |
print "sort = %s" % qsort(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment