Guest User

Untitled

a guest
Dec 2nd, 2015
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def partition(L):
  2.     j = 0
  3.  
  4.     for i in range(1, len(L)):
  5.         val = L[i]
  6.         k = i
  7.        
  8.         while k > j and val < 0:
  9.             L[k] = L[k - 1]
  10.             k -= 1
  11.            
  12.             if j == k:
  13.                 j += 1
  14.  
  15.         L[k] = val
  16.  
  17. L = [9, 2, -3, 1, 0, 0, -7, -6, 3, -5, 2]
  18. partition(L)
  19.  
  20. # result: [-3, -7, -6, -5, 9, 2, 1, 0, 0, 3, 2]
Advertisement
Add Comment
Please, Sign In to add comment