By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Possibly just delete the function and start again.

In any case sorting is a function which has a bunch of solutions - are you looking for any solution or for an efficient solution?

If you're looking for an efficient solution quicksort (http://en.wikipedia.org/wiki/Quicksort) is something every programmer should eventually know how to implement, however in place quicksort is actually reasonably hard to get your head around. If you don't need an efficient solution I recommend bubble sort - it has terrible efficiency (average case O(n^2)) but is ridiculously simply to write. http://en.wikipedia.org/wiki/Bubble_sort

 

Edit:

Heres a terribly optimised version of your assignment I wrote in Python to give you the idea of how bubble sort works

 

from random import sample

 

def sort(arr):

    for n in range(1, len(arr)):

        for i in range(1,len(arr)):

            if(arr[ i] > arr[i-1]):

                tmp = arr[ i]

                arr[ i] = arr[i-1]

                arr[i-1] = tmp

 

arr = sample(xrange(250),100)

sort(arr)

print(arr)