For development environment settings, see: pictures and run application
shellsort
#include <iostream>
#include <vector>
using namespace std;
template <typename Comparable>
void shellsort(vector<Comparable> &a)
{
for(int gap = a.size() / 2; gap > 0; gap /= 2){
for(int i = gap; i < a.size(); ++i)
{
Comparable tmp = move(a[i]);
int j = i;
for (; j >= gap && tmp < a[j - gap]; j -= gap)
{
a[j] = move(a[j - gap]);
}
a[j] = move(tmp);
}
cout<< "\n" << gap << endl;
for (int n : a)
cout << n << ' ';
}
}
int main() {
vector<int> a = { 81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15};
shellsort(a);
return 0;
}
- Warn info
warning: comparison of integer expressions of different signedness:
'int' and 'std::vector<int>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
10 | for(int i = gap; i < a.size(); ++i)