#include "stdafx.h"
#include<iostream>;
using namespace std;
void print(int a[], int n){
for (int j = 0; j < n; j++){
cout << a[j] <<" ";
}
cout << endl;
}
void ShellInsertSort(int a[], int n, int dk){
for (int i = dk; i < n; i++){
if (a[i] < a[i - dk]){
int j = i - dk;
int x = a[i];
a[i] = a[j];
while (x < a[j])
{
a[j + dk] = a[j];
j -= dk;
}
a[j + dk] = x;
}
print(a, n);
}
}
void ShellSort(int a[], int n){
int dk = n / 2;
while (dk >= 1)
{
ShellInsertSort(a, n, dk);
dk /= 2;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[9] = { 3, 1, 5, 7, 2, 4, 9, 6,11 };
ShellSort(a, 9);
print(a, 9);
return 0;
}
#include<iostream>;
using namespace std;
void print(int a[], int n){
for (int j = 0; j < n; j++){
cout << a[j] <<" ";
}
cout << endl;
}
void ShellInsertSort(int a[], int n, int dk){
for (int i = dk; i < n; i++){
if (a[i] < a[i - dk]){
int j = i - dk;
int x = a[i];
a[i] = a[j];
while (x < a[j])
{
a[j + dk] = a[j];
j -= dk;
}
a[j + dk] = x;
}
print(a, n);
}
}
void ShellSort(int a[], int n){
int dk = n / 2;
while (dk >= 1)
{
ShellInsertSort(a, n, dk);
dk /= 2;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[9] = { 3, 1, 5, 7, 2, 4, 9, 6,11 };
ShellSort(a, 9);
print(a, 9);
return 0;
}