I was also wondering if you could write a pseudo code to explain the algorihthm
public class InsertionSorter
{
public static int[ ] sort(int[ ] list)// passes an array list to sort
{
for (int i = 1; i < list.length; i++)// outer loop goin through list starts at 1 coz we need to check index 1 value
{
int value = list[i]; // local variable initialised holds value
int j = i-1;// get previous index
while (j >= 0 && list[j] > value)// inner loop condition 2 check if greater than/= 0 and greater than previous number
{
list[j + 1] = list[j]; // move until j is less than value
j = j-1; // next number
}
list[j+1] = value; // set value
}
return list;
}
}
2007-12-13
04:23:37
·
3 answers
·
asked by
sprite
3
in
Computers & Internet
➔ Programming & Design