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 <iostream> 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:" <<endl; shell_sort(x, 10); std::cout << "Result:" <<std::endl; for (int i = 0; i < 10; i++){ std::cout << x[i] << "\t"; } std::cout << std::endl; return 0; } -- Summary: Different exists with and without standard output. Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: chenclf at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42023