Click to See Complete Forum and Search --> : insertion sort


sh33p1985
11-08-2004, 11:11 AM
can you help me, how do i implement the insertion sort algorithm? as simple as possible acting on an array array

Philwx
11-09-2004, 10:59 PM
Don't take this the wrong way, but It's hard to help you on this without doing the whole thing for you. I'll just say this:

What is the algorithm?

Given an array of items to be sorted:

1) Make a secondary array (of equal size) to store the sorted list.

2) Find the smallest value in the original array.

3) Stick that smallest value in the secondary array.

4) Delete that smallest value from the original array so it isn't used again.

5) Repeat starting at step 2 until the original array is empty.

6) The secondary array is now fully sorted.