Good afternoon. Help me to make some things. In the output should be the time that the sorting took and the complexity of sorting( how many operations the program made). Thanks!
int shellSort(int arr[], int n, int &nswaps)
{
for (int gap = n / 2; gap > 0; gap /= 2)
{
for (int i = gap; i < n; i += 1)
{
int temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) {
nswaps++;
arr[j] = arr[j - gap];
}
arr[j] = temp;
}
}
return 0;
}
int main()
{
...
int nswaps = 0;
shellSort(arr, N, nswaps);
...
// some computation of N and nswaps
just put the gap in an array and get one of the good ones from the wiki. The one you used is poor and will make the algorithm look poor.
the better sequences have the form O(N)^(x+1/x) eg O(N)^7/6
however the sequence you use for gap changes the run time analysis dramatically. It can be anything from n*n (gap is just 1, no sequence used) to very close to logbased and a variety in between.
a computer < 5 years old should manage 3-5 million subsecond.