Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #coding: utf-8
- import random
- num = ''
- while not num.isdigit():
- num = raw_input('配列の個数を入力: ')
- num = int(num)
- def quicksort(seq):
- if len(seq) < 1:
- return seq
- pivot = seq[0]
- left = []
- right = []
- for x in range(1, len(seq)):
- if seq[x] <= pivot:
- left.append(seq[x])
- else:
- right.append(seq[x])
- left = quicksort(left)
- right = quicksort(right)
- return left + [pivot] + right
- if __name__ == '__main__':
- ary = []
- for n in range(num):
- ary.append(random.randint(1,num*10))
- print '\n変換前:'
- print str(ary)
- print '\n変換後:'
- print str(quicksort(ary))
- print ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement