[Python] Trying to make a sorted array of the indexes of another array in an extremely limited...

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to make a sorting function that will make an array of the indexes of the "input array."

    Eg. Array(19,21,15,50,14) would return Array(4,2,0,1,3)

    That may sound easy, but the version of "python" I am using is very limited. (Don't ask which or why it's in quotes, that's not the point.) Here are the limitations:

    • Cannot pass variables through functions (return, and stuff like def func(var2, var1)), but I can use them to change the values of global variables
    • Cannot use embedded arrays
    • Cannot use any "pre-built" python functions like sort() or something
    • Cannot change the values of 2 variables in the same line, e.g. var1,var2 = var2,var1

    I'm looking for a way to do this with the lowest time complexity. I feel like I know how to do this with a bubble sort or insertion sort, but the array I'll need to sort is 41 items long...

    I've tried to write mergesorts and quicksorts since they have low time complexity but I have no idea how to do them without carrying variables between functions.

    If you do come up with an algorithm please write it in python so that I can translate it into my very cool version of python.

    Continue reading...

Compartilhe esta Página