Results 1 to 1 of 1
- 01-17-2010, 06:09 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
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;
}
}
Similar Threads
-
Scanner, while loop and sorting arrays/string?
By RSYR in forum New To JavaReplies: 10Last Post: 04-20-2011, 06:13 PM -
Sorting Arrays by enum
By sahity1a@yahoo.com in forum New To JavaReplies: 3Last Post: 11-26-2009, 09:08 AM -
How to change Bubble+Selection+Insertion Sorts to Sort String Values?
By VinceGuad in forum New To JavaReplies: 3Last Post: 01-26-2009, 12:20 AM -
Arrays, Iteration and selection (Cache)
By dietgal in forum New To JavaReplies: 17Last Post: 10-11-2008, 07:44 AM -
Using PreparedStatement for insertion
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks