gnome sort is not best sorting algorithms but sure it takes its pride it has time on2 examples gnomesort0 5 2 3 2 0 2 2 3 5 gnomesort gnomesort2 45 5 45 5 2 first case while loop swap examples gnome_sort 0 5 2 3 2 0 2 2 3 5 gnome_sort gnome_sort 2 45 5 45 5 2 first case while loop swap
def gnome_sort(arr):
    

    
    size = len(arr)

    if size <= 1:
        return arr
    ind = 0
    
    while ind < size:
        if ind == 0:
            ind += 1
        elif arr[ind] >= arr[ind - 1]:
            ind += 1
        else:
            
            temp = arr[ind - 1]
            arr[ind - 1] = arr[ind]
            arr[ind] = temp
            ind -= 1

    return arr