Fixed Python2 vs Python3 division compatibility.

This commit is contained in:
Donne Martin
2015-07-06 06:44:35 -04:00
parent 9df39726c1
commit 40ef096ede

View File

@@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a naiive solution sufficient (ie not in-place)?\n", "* Is a naiive solution sufficient (ie not in-place)?\n",
" * Yes" " * Yes"
] ]
@@ -88,12 +87,14 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from __future__ import division\n",
"\n",
"def quick_sort(data):\n", "def quick_sort(data):\n",
" if len(data) < 2:\n", " if len(data) < 2:\n",
" return data\n", " return data\n",
" left = []\n", " left = []\n",
" right = []\n", " right = []\n",
" pivot_index = len(data) / 2\n", " pivot_index = int(len(data) / 2)\n",
" pivot_value = data[pivot_index]\n", " pivot_value = data[pivot_index]\n",
" \n", " \n",
" # Build the left and right partitions\n", " # Build the left and right partitions\n",