I have to sort an array using insertion sort (where you take the # after the number you are checking and switch them if that number is larger)
I also have to count the # of operations that the sort goes through (ie - for loop = 3)
My code right now is this:
public static int selectionSort(int[] list)
{
int count = 0;
for (int i=0; i<list.length-1; i++)
{
count +=3;
if (list > list[i+1])
{
int temp = list;
list = list [i+1];
list [i+1] = temp;
count +=3;
}
}
return count;
}
I also have to count the # of operations that the sort goes through (ie - for loop = 3)
My code right now is this:
public static int selectionSort(int[] list)
{
int count = 0;
for (int i=0; i<list.length-1; i++)
{
count +=3;
if (list > list[i+1])
{
int temp = list;
list = list [i+1];
list [i+1] = temp;
count +=3;
}
}
return count;
}