Skip to content
Advertisement

Order a list of numbers without built-in sort, min, max function

If I have a list that varies in length each time and I want to sort it from lowest to highest, how would I do that?

If I have: [-5, -23, 5, 0, 23, -6, 23, 67]

I want: [-23, -6, -5, 0, 5, 23, 23, 67]

I start with this:

JavaScript

BUT this only goes through once and I get:

JavaScript

This is where I get stuck.

How do I keep looping through until the len(new_list) = len(data_list) (i.e. all the numbers are in the new list) with everything sorted without using the built in max, min, sort functions? I’m not sure if it’s necessary to create a new list either.

Advertisement

Answer

I guess you are trying to do something like this:

JavaScript

#Added parenthesis

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement