Hello,
I have a problem with qsort. I let my program generate 50x40 arrays and after i used qsort. The result is not 50x40 anymore. It become a
here is my code
Code:#include <iostream> #include <ctime> #include <cstdlib> #include <iomanip> using namespace std; int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main() { const int row=50; const int column=40; int table[row][column]; int rnum; int t[row]; srand(time(0)); rnum = (rand() % 100) + 1; for(int r=0; r<row; r++)//row { for(int c=0; c<column; c++) table [r][c] = (rand()%100) + 1; } for(int r=0; r<row; r++)//row { for(int c=0; c<column; c++) //column { cout << setw(3) << table[r][c] << ' '; //display table } cout << endl; } qsort(table, 50 * 40, sizeof(int), compare); cout << "your new sorted table is: \n"; for(int n=0; n<row; n++)//row { for(int m=0; m<column; m++) //column { cout << setw(3) << table[n][m] << ' '; //display table } } system("pause"); return 0; }



LinkBack URL
About LinkBacks


