Polish selection sort solution

This commit is contained in:
Donne Martin 2016-02-24 07:37:31 -05:00
parent 577ada7896
commit d8ac0b8fc6

View File

@ -86,14 +86,11 @@
"outputs": [],
"source": [
"def selection_sort(data):\n",
" if data is None:\n",
" if data is None or len(data) < 2:\n",
" return\n",
" size = len(data)\n",
" for i in range(size):\n",
" if i == size - 1:\n",
" break\n",
" for i in range(len(data)-1):\n",
" min_index = i\n",
" for j in range(i + 1, size):\n",
" for j in range(i + 1, len(data)):\n",
" if data[j] < data[min_index]:\n",
" min_index = j\n",
" data[i], data[min_index] = data[min_index], data[i]"
@ -136,9 +133,7 @@
"\n",
"\n",
"def selection_sort_iterative_alt(data):\n",
" if data is None:\n",
" return None\n",
" if len(data) == 0 or len(data) == 1:\n",
" if data is None or len(data) < 2:\n",
" return\n",
" for i in range(0, len(data) - 1):\n",
" swap(data, i, find_min_index(data, i))"