# Need help with sorting 2d arrays (insertion and selection)

• 01-17-2010, 07:09 AM
mjunit
Need help with sorting 2d arrays (insertion and selection)
How do i create a selection, or insertion sort to sort this array filled with random numbers:

int[][] arrayForRandomNumbers = new int [12][15];

any ideas??

Also, can u tell me what kind of sort this person is using?

int[][] sortnum = new int [12][15];

public int[][] sortingArray (int sortnum[][]){
int row,col,temp;
for (int a = 0 ; a < sortnum.length; a++ ){
for ( int b = 0 ; b < sortnum[a].length ; b++){
col = a;
row = b;
while (col != -1 && row!= -1){
if (row != 0){
if (sortnum[col][row] >= sortnum[col][row - 1]){
temp = sortnum[col][row-1] ;
sortnum[col][row-1]= sortnum[col][row];
sortnum[col][row] = temp;
}
}
else if ( row==0 && col!= 0){
if (sortnum[col][row] >= sortnum[col-1][14]){
temp =sortnum[col-1][14] ;
sortnum[col-1][14]= sortnum[col][row];
sortnum[col][row] = temp;
}
}
if (row!=0){
row--;
}
else if (row==0){
col--;
row = 14;
}
}