Here is my code compiled with "g++ -Wall shell_sort.cpp"
The problem is that the result is different without the standard output in the
shell "shell_sort" function.
Would you please explain why this happens in my program?
#include
using namespace std;
void shell_sort(int *x, int m)
{
int h;
while (h > 0){
for (int i = 0; i < m; i++){
int temp = x[i], j = i;
while ((j >= h) && (x[j-h] > temp)){
x[j] = x[j - h];
j -= h;
}
x[j] = temp;
}
// cout << endl;
if ((h / 2) != 0){
h /= 2;
}else if (h == 1){
h = 0;
}else{
h = 1;
}
}
}
int main()
{
int *x = new int[10];
for (int i = 0; i < 10; i++){
x[i] = 30 - 3*i;
}
std::cout << "Original:" << std::endl;
for (int i = 0; i < 10; i++){
std::cout << x[i] << "\t";
}
std::cout << std::endl;
cout << "Output:"