Hi & Happy New Year!!! I was wondering if anyone can tell me why my array sort works ONLY if the array is
less than 11? (making my n double digits 10).
the putput once the array goes greater than 10 gives me a long
negative number at the BEginning of the sort, and if i go MUCH higher than 10 say 20, i get proportionally more of the same negative number.
Hmm just want to know where my bug is.
thanks everyone!
Mouse
ps here is my code
Code:#include <iostream.h> #include<fstream.h> void bubble_Sort( int arr[], int n ); ifstream infile("C:\\CODE\\IN.txt"); ofstream outfile("C:\\CODE\\of.txt"); void main() { if(!infile){ cerr << "Cannot open input file" << endl; } if(!outfile){ cerr << "Cannot open output file" << endl; } int arr[10]; for (int i =0; i< 9; i++) infile >> arr[i]; bubble_Sort( arr, i-1); for ( i =0; i< 9; i++) cout<<"\n"<<arr[i]; } // Bubble Sort void bubble_Sort( int arr[], int n) { for (int i=0; i<= n; i++) for(int j=0; j<= n-i-1; j++) if ( arr[j] > arr[j+1] ) { int tmp = arr[j+1]; arr[j+1] = arr[j]; arr[j] = tmp; } }



LinkBack URL
About LinkBacks


