Permalink
Browse files

use randomized partition

  • Loading branch information...
1 parent a3c6f7e commit 88bbac1ab6ed2a801edbc575aa9cb4cf79711c30 Lorenzo Bolla committed May 22, 2012
Showing with 9 additions and 9 deletions.
  1. +9 −9 google/order.py
View
18 google/order.py
@@ -1,5 +1,4 @@
-# from qsort import random_partition as partition
-from qsort import partition as partition
+from qsort import random_partition as partition
def order(A, p, r, i):
@@ -17,10 +16,11 @@ def order(A, p, r, i):
return order(A, q + 1, r, i - k)
-A = [4,6,5,2,1,3,4,5]
-print sorted(A)
-print order(A, 0, len(A) - 1, 1) # 1
-print order(A, 0, len(A) - 1, 2) # 2
-print order(A, 0, len(A) - 1, 3) # 3
-print order(A, 0, len(A) - 1, 5) # 4
-print order(A, 0, len(A) - 1, 6) # 5
+if __name__ == '__main__':
+ A = [4,6,5,2,1,3,4,5]
+ print sorted(A)
+ print order(A, 0, len(A) - 1, 1) # 1
+ print order(A, 0, len(A) - 1, 2) # 2
+ print order(A, 0, len(A) - 1, 3) # 3
+ print order(A, 0, len(A) - 1, 5) # 4
+ print order(A, 0, len(A) - 1, 6) # 5

0 comments on commit 88bbac1

Please sign in to comment.