Skip to content

Instantly share code, notes, and snippets.

@amano41
Created January 26, 2013 01:48
Show Gist options
  • Save amano41/4639572 to your computer and use it in GitHub Desktop.
Save amano41/4639572 to your computer and use it in GitHub Desktop.
Python の練習でクイックソートを書いてみました。
#! /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