{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 程序流程"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**1.利用while输出1 2 3 4 5 6 8 9 10**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t8\t9\t10\t"
     ]
    }
   ],
   "source": [
    "i = 1\n",
    "while i<=10:\n",
    "    if i!=7:\n",
    "         print(i,end = '\\t')\n",
    "         i += 1\n",
    "    else:\n",
    "        i+=1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**2.求1-100所有数的和**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "for i in range(1,101):\n",
    "    sum = sum+i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "i=0\n",
    "while i<101:\n",
    "    sum = sum+i\n",
    "    i=i+1\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "101"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**3.输出1-100内所有奇数、偶数**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 "
     ]
    }
   ],
   "source": [
    "for i in range(1,101):\n",
    "    if i % 2 !=0:\n",
    "        print (i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 "
     ]
    }
   ],
   "source": [
    "for i in range(1,101,2):\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5.求1+3+5+....+99的和**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2500\n"
     ]
    }
   ],
   "source": [
    "sum=0\n",
    "for i in range(1,101):\n",
    "    if i % 2 !=0:\n",
    "        sum=sum+i\n",
    "print (sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2500\n"
     ]
    }
   ],
   "source": [
    "sum=0\n",
    "for i in range(1,101,2):\n",
    "        sum=sum+i\n",
    "print (sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**6.模拟用户登录（三次机会重试）**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "i=1 \n",
    "while i<=3:    \n",
    "    user = input('请输入用户名--->')    \n",
    "    pswd =input('请输入密码--->')    \n",
    "    if user == 'admin' and pswd == 'admin123':        \n",
    "        print('登陆成功')        \n",
    "        break    \n",
    "    else:        \n",
    "        print('用户名或密码错误','还有', 3-i ,'次机会')        \n",
    "        i+=1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**综合训练输出乘法99表**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 * 1 = 1\t\n",
      "1 * 2 = 2\t2 * 2 = 4\t\n",
      "1 * 3 = 3\t2 * 3 = 6\t3 * 3 = 9\t\n",
      "1 * 4 = 4\t2 * 4 = 8\t3 * 4 = 12\t4 * 4 = 16\t\n",
      "1 * 5 = 5\t2 * 5 = 10\t3 * 5 = 15\t4 * 5 = 20\t5 * 5 = 25\t\n",
      "1 * 6 = 6\t2 * 6 = 12\t3 * 6 = 18\t4 * 6 = 24\t5 * 6 = 30\t6 * 6 = 36\t\n",
      "1 * 7 = 7\t2 * 7 = 14\t3 * 7 = 21\t4 * 7 = 28\t5 * 7 = 35\t6 * 7 = 42\t7 * 7 = 49\t\n",
      "1 * 8 = 8\t2 * 8 = 16\t3 * 8 = 24\t4 * 8 = 32\t5 * 8 = 40\t6 * 8 = 48\t7 * 8 = 56\t8 * 8 = 64\t\n",
      "1 * 9 = 9\t2 * 9 = 18\t3 * 9 = 27\t4 * 9 = 36\t5 * 9 = 45\t6 * 9 = 54\t7 * 9 = 63\t8 * 9 = 72\t9 * 9 = 81\t\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(1,i+1):\n",
    "        print (j,\"*\",i,\"=\",i*j,end=\"\\t\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(2,end='')\n",
    "print(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**打印菱形**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"aa\"*2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   *\n",
      "  ***\n",
      " *****\n",
      "*******\n",
      " *****\n",
      "  ***\n",
      "   *\n"
     ]
    }
   ],
   "source": [
    "for i in range(-3,4):\n",
    "    if i<0 :\n",
    "        prespace = -i\n",
    "    else:\n",
    "        prespace = i\n",
    "    print(' '*prespace + '*'*(7-prespace*2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   *\n",
      "  **\n",
      " ***\n",
      "*******\n",
      "   ***\n",
      "   **\n",
      "   *\n"
     ]
    }
   ],
   "source": [
    "for i in range(-3,4):\n",
    "    if i<0:\n",
    "        print(' '*-i + '*'*(4+i))\n",
    "    elif i>0:\n",
    "        print(' '*3+'*'*(4-i))\n",
    "    else:\n",
    "        print('*'*7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " *******\n",
      "  *****\n",
      "   ***\n",
      "    *\n",
      "   ***\n",
      "  *****\n",
      " *******\n"
     ]
    }
   ],
   "source": [
    "for i in range(-3,4):\n",
    "    if i<0:\n",
    "        j=-i\n",
    "    else:\n",
    "        j=i\n",
    "    print(' '*(9//2 -j)+'*'*(2*j + 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "print(3)\n",
    "print(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\t4\n"
     ]
    }
   ],
   "source": [
    "# print()函数默认结束符号是end='/n',如果要连续打印那么输出应该end=‘’\n",
    "# 要分隔开end='\\t'\n",
    "print(3,end='')\n",
    "print(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"123\"\n",
    "print(type(a),a)# type(a)表示a的数据类型\n",
    "b = int(a)\n",
    "print(type(b),b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#当前数字的二进制，至少用n位表示\n",
    "a = 18\n",
    "n = a.bit_length()\n",
    "print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = [3,44,38,5,47,15,36,26,27,2,46,4,19,50,48]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 5, 15, 19, 26, 27, 36, 38, 44, 46, 47, 48, 50]\n"
     ]
    }
   ],
   "source": [
    "a.sort()\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**1.冒泡排序**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bubbleSort(arr):\n",
    "    for i in range(1, len(arr)):\n",
    "        for j in range(0, len(arr)-i):\n",
    "            if arr[j] > arr[j+1]:\n",
    "                arr[j], arr[j + 1] = arr[j + 1], arr[j]\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bubbleSort([3,6,7,2,9,0,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](冒泡排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**2.选择排序**<br/>\n",
    "选择排序是一种简单直观的排序算法，无论什么数据进去都是 O(n²) 的时间复杂度。<br/>所以用到它的时候，数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def selectionSort(arr):\n",
    "    for i in range(len(arr) - 1):\n",
    "        # 记录最小数的索引\n",
    "        minIndex = i\n",
    "        for j in range(i + 1, len(arr)):\n",
    "            if arr[j] < arr[minIndex]:\n",
    "                minIndex = j\n",
    "        # i 不是最小数时，将 i 和最小数进行交换\n",
    "        if i != minIndex:\n",
    "            arr[i], arr[minIndex] = arr[minIndex], arr[i]\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "selectionSort([3,44,38,5,47,15,36,26,27,2,46,4,19,50,48])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](选择排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**3.插入排序**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def insertionSort(arr):\n",
    "    for i in range(len(arr)):\n",
    "        preIndex = i-1\n",
    "        current = arr[i]\n",
    "        while preIndex >= 0 and arr[preIndex] > current:\n",
    "            arr[preIndex+1] = arr[preIndex]\n",
    "            preIndex-=1\n",
    "        arr[preIndex+1] = current\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "selectionSort([3,44,38,5,47,15,36,26,27,2,46,4,19,50,48])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](插入排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**4.希尔排序**<br/>\n",
    " \n",
    "希尔排序，也称递减增量排序算法，是插入排序的一种更高效的改进版本。<br/>但希尔排序是非稳定排序算法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def shellSort(arr):\n",
    "    import math\n",
    "    gap=1\n",
    "    while(gap < len(arr)/3):\n",
    "        gap = gap*3+1\n",
    "    while gap > 0:\n",
    "        for i in range(gap,len(arr)):\n",
    "            temp = arr[i]\n",
    "            j = i-gap\n",
    "            while j >=0 and arr[j] > temp:\n",
    "                arr[j+gap]=arr[j]\n",
    "                j-=gap\n",
    "            arr[j+gap] = temp\n",
    "        gap = math.floor(gap/3)\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5.归并排序**<br/>\n",
    " \n",
    "归并排序（Merge sort）是建立在归并操作上的一种有效的排序算法。<br/>该算法是采用分治法（Divide and Conquer）的一个非常典型的应用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mergeSort(arr):\n",
    "    import math\n",
    "    if(len(arr)<2):\n",
    "        return arr\n",
    "    middle = math.floor(len(arr)/2)\n",
    "    left, right = arr[0:middle], arr[middle:]\n",
    "    return merge(mergeSort(left), mergeSort(right))\n",
    "\n",
    "def merge(left,right):\n",
    "    result = []\n",
    "    while left and right:\n",
    "        if left[0] <= right[0]:\n",
    "            result.append(left.pop(0));\n",
    "        else:\n",
    "            result.append(right.pop(0));\n",
    "    while left:\n",
    "        result.append(left.pop(0));\n",
    "    while right:\n",
    "        result.append(right.pop(0));\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5, 15, 19, 26, 27, 36, 38, 44, 46, 47, 48, 50]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mergeSort([3,44,38,5,47,15,36,26,27,2,46,4,19,50,48])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](归并排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**6.快速排序**<br/>\n",
    " \n",
    "快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下，排序 n 个项目要 Ο(nlogn) 次比较。<br/>\n",
    "在最坏状况下则需要 Ο(n2) 次比较，但这种状况并不常见。事实上，快速排序通常明显比其他 Ο(nlogn) 算法更快，<br/>\n",
    "因为它的内部循环（inner loop）可以在大部分的架构上很有效率地被实现出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def quickSort(arr, left=None, right=None):\n",
    "    left = 0 if not isinstance(left,(int, float)) else left\n",
    "    right = len(arr)-1 if not isinstance(right,(int, float)) else right\n",
    "    if left < right:\n",
    "        partitionIndex = partition(arr, left, right)\n",
    "        quickSort(arr, left, partitionIndex-1)\n",
    "        quickSort(arr, partitionIndex+1, right)\n",
    "    return arr\n",
    "\n",
    "def partition(arr, left, right):\n",
    "    pivot = left\n",
    "    index = pivot+1\n",
    "    i = index\n",
    "    while  i <= right:\n",
    "        if arr[i] < arr[pivot]:\n",
    "            swap(arr, i, index)\n",
    "            index+=1\n",
    "        i+=1\n",
    "    swap(arr,pivot,index-1)\n",
    "    return index-1\n",
    "\n",
    "def swap(arr, i, j):\n",
    "    arr[i], arr[j] = arr[j], arr[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5, 15, 19, 26, 27, 36, 38, 44, 46, 47, 48, 50]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quickSort([3,44,38,5,47,15,36,26,27,2,46,4,19,50,48])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](快速排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**7. 堆排序**<br/>\n",
    " \n",
    "堆排序（Heapsort）是指利用堆这种数据结构所设计的一种排序算法。堆积是一个近似完全二叉树的结构，并同时满足堆积的性质：\n",
    "<br/>即子结点的键值或索引总是小于（或者大于）它的父节点。<br/>堆排序可以说是一种利用堆的概念来排序的选择排序。\n",
    "\n",
    "分为两种方法：\n",
    "* 大顶堆：每个节点的值都大于或等于其子节点的值，在堆排序算法中用于升序排列；\n",
    "* 小顶堆：每个节点的值都小于或等于其子节点的值，在堆排序算法中用于降序排列；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def buildMaxHeap(arr):\n",
    "    import math\n",
    "    for i in range(math.floor(len(arr)/2),-1,-1):\n",
    "        heapify(arr,i)\n",
    "\n",
    "def heapify(arr, i):\n",
    "    left = 2*i+1\n",
    "    right = 2*i+2\n",
    "    largest = i\n",
    "    if left < arrLen and arr[left] > arr[largest]:\n",
    "        largest = left\n",
    "    if right < arrLen and arr[right] > arr[largest]:\n",
    "        largest = right\n",
    "\n",
    "    if largest != i:\n",
    "        swap(arr, i, largest)\n",
    "        heapify(arr, largest)\n",
    "\n",
    "def swap(arr, i, j):\n",
    "    arr[i], arr[j] = arr[j], arr[i]\n",
    "\n",
    "def heapSort(arr):\n",
    "    global arrLen\n",
    "    arrLen = len(arr)\n",
    "    buildMaxHeap(arr)\n",
    "    for i in range(len(arr)-1,0,-1):\n",
    "        swap(arr,0,i)\n",
    "        arrLen -=1\n",
    "        heapify(arr, 0)\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](堆排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**8.计数排序**<br/>\n",
    " \n",
    "计数排序的核心在于将输入的数据值转化为键存储在额外开辟的数组空间中。<br/>\n",
    "作为一种线性时间复杂度的排序，计数排序要求输入的数据必须是有确定范围的整数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def countingSort(arr, maxValue):\n",
    "    bucketLen = maxValue+1\n",
    "    bucket = [0]*bucketLen\n",
    "    sortedIndex =0\n",
    "    arrLen = len(arr)\n",
    "    for i in range(arrLen):\n",
    "        if not bucket[arr[i]]:\n",
    "            bucket[arr[i]]=0\n",
    "        bucket[arr[i]]+=1\n",
    "    for j in range(bucketLen):\n",
    "        while bucket[j]>0:\n",
    "            arr[sortedIndex] = j\n",
    "            sortedIndex+=1\n",
    "            bucket[j]-=1\n",
    "    return arr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![alt text](计数排序.gif)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
