-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsoncode.json
1 lines (1 loc) · 873 Bytes
/
jsoncode.json
1
{"language": "python", "domain": "algorithm", "source": "https://github.com/jiaoxn/SortAlgorithm/blob/82ddddd9068ab779b8586f1a40272956fc4fd687/ExchangeSort/bubble_sort.py#L18", "prompt": "def bubble_sort(lists):\n \"\"\"\n \u5b9e\u73b0\u5192\u6ce1\u6392\u5e8f\n Args:\n lists: list\n \u5f85\u6392\u5e8f\u7684\u6570\u7ec4\n return \u6392\u597d\u5e8f\u7684\u6570\u7ec4\n \"\"\"\n", "solution": " length = len(lists)\n\n for i in range(0, length):\n did_swap = False\n\n for j in range(0, length - 1 - i):\n if lists[j] > lists[j + 1]:\n lists[j], lists[j + 1] = lists[j + 1], lists[j]\n did_swap = True\n\n if did_swap is False:\n return lists\n", "test": "assert bubble_sort([3,1,0,12,3])==[0, 1, 3, 3, 12]\nassert bubble_sort([0,34,1,4,1])==[0, 1, 1, 4, 34]"}