bubble sort python
def bubbleSort(lis): length = len(lis) for i in range(length): for j in range(length - i): a = lis[j] if a != lis[-1]: b = lis[j + 1] if a > b: lis[j] = b lis[j + 1] = a return lis
bubble sort python
def bubbleSort(lis): length = len(lis) for i in range(length): for j in range(length - i): a = lis[j] if a != lis[-1]: b = lis[j + 1] if a > b: lis[j] = b lis[j + 1] = a return lis
bubble sort python
def bubble_sort(arr): def swap(i, j): arr[i], arr[j] = arr[j], arr[i] n = len(arr) swapped = True x = -1 while swapped: swapped = False x = x + 1 for i in range(1, n-x): if arr[i - 1] > arr[i]: swap(i - 1, i) swapped = True return arr
Bubble Sort Algorithm in Python
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Mar 10 18:05:51 2019 @note: Exchanging sort - Bubble Sort algorithm @source: http://interactivepython.org/runestone/static/pythonds/SortSearch/TheBubbleSort.html """ def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us