you could also use a recursive function.
There is a problem with your question though: define ascending order. A list can be visualized many different ways, and it's generally a good thing to just think of it as an abstract object.
ex:
1 2 3 4 5 6 7 8
could also be represented as
or even in reverse! It depends on how you want to program the 'read' functions, depending on what you're using it for.
I assume you mean from least to greatest, though.
I'm not giving you the code, but I will write up some psuedo for you. I, personally, templated this.
void sort stuff(your list&)
{
-if the lists size is less than two, return
-go through the list and store the smallest value in a temp variable
-resize the list to 1 less than it's current size (you can swap the smallest value with the last to prevent data loss)
-call this function
-add the temp variable you stored the smallest value in, back into the list.
} |
if it's in the wrong order (fro greatest to least instead of least to greatest) then simply flip the sign to take out the largest value.