We discussed the insert sort today. I thought I would share it with those of you whom may have not seen it before. This actually performs no swapping operations at all.
What did everyone else learn?Code:
void insertSort(int x[], int n)
{
//O(log2(n))
int i, k, y;
for(k = 1;k < n;k++)
{
y = x[k];
for(i = k - 1;i >= 0 && y < x[i];i--)
x[i+1] = x[i];
x[i+1] = y;
}
}