S
StudiousStudent
Guest
I'm new to using C#, I have some C++ experiance. I wish to collect some data at every j*=3 intervals to see the efficiency of this InsertionSort algorithm. I'm not sure how I can do this without the need of my if statement. I'll be using a stopwatch class to collect the time data I desire. Any help would be appreciated.
static void insertionSort(ref int[] input)
{
int i, j, key;
for (j = 1; j < input.Length; j++)
{
key = input[j];
i = j - 1;
while (i >= 0 && input > key)
{
input[i + 1] = input;
i--;
}
input[i + 1] = key;
if ( j == 1 || j == 3 || j == 9 || j == 27 || j == 81 || j == 243 || j == 729 || j == 2187 || j == 6561 || j == 19683 || j == 59049 || j == 177147 )
{
// DO SOMETHING
}
}
}
StudiousStudent
Continue reading...
static void insertionSort(ref int[] input)
{
int i, j, key;
for (j = 1; j < input.Length; j++)
{
key = input[j];
i = j - 1;
while (i >= 0 && input > key)
{
input[i + 1] = input;
i--;
}
input[i + 1] = key;
if ( j == 1 || j == 3 || j == 9 || j == 27 || j == 81 || j == 243 || j == 729 || j == 2187 || j == 6561 || j == 19683 || j == 59049 || j == 177147 )
{
// DO SOMETHING
}
}
}
StudiousStudent
Continue reading...