"but I really am crap at sorts of all kinds"
What you are not doing here is helping yourself. Getting other people to do your work for you is not going to make you any better.
A good place to start learning about insertion sort would be the Wikipedia article. But because you seem like you're in a hurry, I'll summarize here.
Say you start off with this random array:
[ 4, 2, 5, 7, 3 ]
The general idea behind insertion sort is that you want to split your array into two sections -- the sorted section and the unsorted section. Every iteration, you pick the first element in the unsorted portion and then insert it into its proper position in the sorted portion of the array.
So to begin, you have this, where the |
represents the split between sorted and unsorted portions, with the sorted portion on the left:
[ | 4, 2, 5, 7, 3]
First you take the first element in the unsorted element in the unsorted array and move it into its proper position in the sorted portion of the array. This is easy, because there is nothing else in the array:
[ 4 | 2, 5, 7, 3 ]
Then you repeat:
[ 2, 4 | 5, 7, 3 ]
[ 2, 4, 5 | 7, 3 ]
[ 2, 4, 5, 7 | 3 ]
[ 2, 3, 4, 5, 7 | ]
And now you're done! Turning this into code shouldn't take anything more than some loops, swaps, and if
statements.
This should be enough to get you started. If you try implementing something and there's a specific thing you're stuck on, try posting here again.