[Python] How do I write a recursive function of sorting in Python? [closed]

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    Been trying to get into recursion lately, and I came up with this in a sorting problem. Here is the code:

    def sort(arr, n):
    if n < 1:
    return arr


    while arr[n] > arr[n-1]:
    tmp = arr[n-1]
    arr[n-1] = arr[n]
    arr[n] = tmp

    return sort(arr, n-1)


    Obviously, it doesn't work so how do I improve it?

    Continue reading...

Compartilhe esta Página