I am trying to write this C++ code which will sort a 2D array, but not sure what parameters to pass when im calling it in the main. Here is the code.
Thanks
Code:
#include<iostream>
using namespace std;
int d[3][5]={{1,2,3,4,5},{10,1,2,1,5},{3,1,3,4,2}}; // array to sort
void selectionSort(int *array,int length)//selection sort function
{
int i,j,min,minat;
for(i=0;i<(length-1);i++)
{
minat=i;
min=array[i];
for(j=i+1;j<(length);j++) //select the min of the rest of array
{
if(min>array[j]) //ascending order for descending reverse
{
minat=j; //the position of the min element
min=array[j];
}
}
int temp=array[i] ;
array[i]=array[minat]; //swap
array[minat]=temp;
}
}
void printElements(int *array,int length) //print array elements
{
int i=0;
for(i=0;i<= d[3][5];i++)
cout<<array[i]<<endl;
}
void main()
{
selectionSort(); //call to selection sort
printElements(); // print elements
system("pause");
//return 0;
}
Thanks