Without seeing your swap
, I say that the culprit is this line:
swap(list, list[i], list[i + gap]);
You are passing the values in positions 2 and 3, where indexes are almost certainly expected. This call should look like this:
swap(list, i, i + gap);
Otherwise, the swap
would interpret the values of the array as indexes to be swapped, reading memory outside the array.
To avoid problems like this in the future, use std::swap
instead:
std::swap(list[i], list[i + gap]);