Code:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int bubbleSort( int[], int);
int main()
{
//const int NROWS = 4;
//const int NCOLS = 5;
//int first[NROWS][NCOLS] = {16,22,99,4,18,-258,4,101,5,98,105,6,15,2,45,33,88,72,16,3};
//int i, j;
const int ARR1 = 20;
int arr[ARR1]= {16,22,99,4,18,-258,4,101,5,98,105,6,15,2,45,33,88,72,16,3};
int i, j;
bubbleSort(arr, ARR1);
for (i = 0; i < ARR1; i++)
{
cout << endl;
for( i = 0; i < ARR1; i++)
cout << " " << arr[i];
}
return 0;
}
int bubbleSort(int num[], int numel)
{
int i, j, temp;
for ( i = 0; i < (numel - 1); i++)
{
for ( j = 1; j < numel; j++)
{
if (num[j] < num[j-1])
{
temp = num[j];
num[j] = num[j - 1];
num[j-1] = temp;
}
}
}
}
I have the 2-dimension part commented out so this code works, it is just with a single dimension.