mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-03 07:58:02 +00:00
Changed xrange to range to be compatible with Python 3.
This commit is contained in:
@@ -88,8 +88,8 @@
|
||||
"def insertion_sort(data):\n",
|
||||
" if len(data) < 2:\n",
|
||||
" return\n",
|
||||
" for r in xrange(1, len(data)):\n",
|
||||
" for l in xrange(0, r):\n",
|
||||
" for r in range(1, len(data)):\n",
|
||||
" for l in range(0, r):\n",
|
||||
" if data[l] > data[r]:\n",
|
||||
" temp = data[r]\n",
|
||||
" data[l+1:r+1] = data[l:r]\n",
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
" pivot_value = data[pivot_index]\n",
|
||||
" \n",
|
||||
" # Build the left and right partitions\n",
|
||||
" for i in xrange(0, len(data)):\n",
|
||||
" for i in range(0, len(data)):\n",
|
||||
" if i == pivot_index:\n",
|
||||
" continue\n",
|
||||
" if data[i] < pivot_value:\n",
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
"source": [
|
||||
"def find_min_index(data, start):\n",
|
||||
" min_index = start\n",
|
||||
" for i in xrange(start + 1, len(data)):\n",
|
||||
" for i in range(start + 1, len(data)):\n",
|
||||
" if data[i] < data[min_index]:\n",
|
||||
" min_index = i\n",
|
||||
" return min_index\n",
|
||||
@@ -121,7 +121,7 @@
|
||||
"def selection_sort_iterative(data):\n",
|
||||
" if len(data) == 0 or len(data) == 1:\n",
|
||||
" return\n",
|
||||
" for i in xrange(0, len(data) - 1):\n",
|
||||
" for i in range(0, len(data) - 1):\n",
|
||||
" swap(data, i, find_min_index(data, i))"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user