You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
506 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//希尔排序
void shellSort(vector<int>v)
{
cout << "希尔排序,升序:" << endl;
int gap = v.size();
while (gap != 1)
{
gap = gap / 3 + 1;
for (int i = gap; i <v.size (); ++i)
{
int temp = v[i];
int j = i - gap;
for (; j >= 0; j -= gap)
{
if (v[j] > temp)
{
v[j + gap] = v[j];
}
else
{
break;
}
}
v[j + gap] = temp;
}
}
printVector(v);
}
//复杂度说明时间复杂度为O(n^1.5)