title: How to implement quick sort on python?
body: <p>maybe I’m the next person who asks how to release quick sort on python correctly. But it’s important for me to know if I wrote this algorithm correctly by reading the pseudocode from the textbook Essential Algorithms: A Practical Approach to Computer Algorithms.</p>
  
  <p>When I run the code, I get this message. RecursionError: maximum recursion depth exceeded in comparison</p>
  
  <pre><code>import random
  
  def quickSort(arr, start, end):
      if start &gt;= end:  # if len(arr) &lt; 2
          return arr
      else:
          divideIndex = partition(arr, start, end)
          quickSort(arr, start, divideIndex - 1)
          quickSort(arr, divideIndex, end)
  
  def partition(arr, head, tail):
      left = head
      right = tail
      pivot = arr[(head + tail) // 2]  # mid
  
      while right &gt;= left:
          # looking through the array from the left
          while arr[left] &lt;= pivot:
              left = left + 1
          # looking through the array from the right
          while arr[right] &gt; pivot:
              right = right - 1
          # found a couple of elements that can be exchanged.
          if left &lt;= right:
              swap(arr[right], arr[left])
              # move the left and right wall
              left = left + 1
              right = right - 1
      # return one elements if not found a couple
      return left
  
  def swap(arr1, arr2):
      temp = arr1
      arr1 = arr2
      arr2 = temp
  
  # Generator random variables
  deck = list(range(50))
  random.shuffle(deck)
  
  
  start = 0
  end = len(deck) - 1
  print(quickSort(deck, start, end))
  </code></pre>