Created
          December 3, 2016 14:09 
        
      - 
      
- 
        Save alisianoi/c39f710b256e3c5d75a9397928479d17 to your computer and use it in GitHub Desktop. 
    Quicksort implementations for the blog
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | def quicksort(xs): | |
| def sort(xs, l, r): | |
| if (l == r): | |
| return | |
| i, j = l, r | |
| pivot = xs[(i + j) / 2] | |
| while (i <= j): | |
| while (xs[i] < pivot): | |
| i += 1 | |
| while (pivot < xs[j]): | |
| j -= 1 | |
| if (i <= j): | |
| xs[i], xs[j] = xs[j], xs[i] | |
| i += 1 | |
| j -= 1 | |
| i, j = 0, len(xs) - 1 | |
| sort(xs, i, j) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment