Ok, the program below sorts the individual rows. I need it to sort all the numbers in each position, not just the rows. Any help would be appreciated.
#include <iostream>
using namespace std;
const int rows = 3;
const int cols = 10;
void select_sort( );
int array[rows][cols]={
{15, 40, 25, 100, 16, 1, 10, 42, 35, 23},
{122, 14, 3, 19, 156, 45, 2, 99, 74, 65},
{0, 34, 39, 109, 176, 20, 7, 18, 29, 12}
};
// ------------------------------------------------------------------
// ------------------------------------------------------------------
int main()
{
int i, j;
cout << "SELECTION SORT PROGRAM" << endl << endl;
cout << "First the unsorted array..." << endl << endl;
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<array[ i ][ j ]<<"\t ";
}
cout<<endl;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
select_sort( );
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
cout<<endl;
cout << "Now the sorted array..." << endl << endl;
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<array[ i ][ j ]<<"\t ";
}
cout<<endl;
}
cout<<endl;
return 0;
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
void select_sort( )
{
int min;
int b;
for(int h=0; h<rows; h++)
{
for(int a=0; a<cols;a++)
{
b=a;
min=array[h];
for(int j=a+1; j<cols;j++)
{
if(array[h][j]<min)
{
b=j;
min=array[h];
}
}
array[h]=array[h][a];
array[h][a]=min;
}
}
return;
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
#include <iostream>
using namespace std;
const int rows = 3;
const int cols = 10;
void select_sort( );
int array[rows][cols]={
{15, 40, 25, 100, 16, 1, 10, 42, 35, 23},
{122, 14, 3, 19, 156, 45, 2, 99, 74, 65},
{0, 34, 39, 109, 176, 20, 7, 18, 29, 12}
};
// ------------------------------------------------------------------
// ------------------------------------------------------------------
int main()
{
int i, j;
cout << "SELECTION SORT PROGRAM" << endl << endl;
cout << "First the unsorted array..." << endl << endl;
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<array[ i ][ j ]<<"\t ";
}
cout<<endl;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
select_sort( );
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
cout<<endl;
cout << "Now the sorted array..." << endl << endl;
for(i=0; i<rows; i++)
{
for(j=0; j<cols; j++)
{
cout<<array[ i ][ j ]<<"\t ";
}
cout<<endl;
}
cout<<endl;
return 0;
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------
void select_sort( )
{
int min;
int b;
for(int h=0; h<rows; h++)
{
for(int a=0; a<cols;a++)
{
b=a;
min=array[h];
for(int j=a+1; j<cols;j++)
{
if(array[h][j]<min)
{
b=j;
min=array[h];
}
}
array[h]=array[h][a];
array[h][a]=min;
}
}
return;
}
// ------------------------------------------------------------------
// ------------------------------------------------------------------