2 ms·
Not sure I agree. I wouldn't have been able to tell you what an insertion sort is, by name. But by looking at that image, I can describe it pretty well: Have
by jerfelix 15y ago
Not sure I agree.
I wouldn't have been able to tell you what an insertion sort is, by name. But by looking at that image, I can describe it pretty well:
Have an outer loop that counts from the first position in the list to the last position (call it n...). At each step in the loop, make sure that the first n items are sorted. This probably implies an inner loop that finds where, within the first n-1 items to insert the nth item. And given that with only one item, it's already sorted, we can probably start with n on the second item.
Yeah, I think I could code that, given the image.