java - Ascending order Sorted array is getting printed in descending order? -
public void sortcolumn(double[] arraytosort) { = new int[5]; (int = 1; < arraytosort.length; i++) { (int j = 1; j < arraytosort.length; j++) { if ((arraytosort[i]) > (arraytosort[j])) { tempvar = arraytosort[j]; arraytosort[j] = arraytosort[i]; arraytosort[i] = tempvar; a[i] = j; } } system.out.println( a[i]); } } public void decisionvalue(double[][] arraydc){ arrtemp = new double[arraydc.length]; for(int =0; i<arraydc[0].length;i++){ system.out.println("the column matrix is"); for(int j =1; j<arraydc.length;j++){ arrtemp[j] = arraydc[j][i]; system.out.println(arrtemp[j]); } sortcolumn(arrtemp); system.out.println("the sorted column matrix is" +i); for(int k =1; k<arraydc.length; k++) system.out.println(arrtemp[k]); } }
by code above sorting columns of array , printing them. don't understand why ascending order sorted elements printed in descending order. please check it. thanks!!
following output: input matrix arraydc
0.0 0.0 0.0
25.0 10.0 24.0
25.0 5.0 23.0
25.0 23.0 6.0
25.0 89.0 8.0
the column matrix 25.0 25.0 25.0 25.0
0 0 0 0
the sorted column matrix is0 25.0 25.0 25.0 25.0
the column matrix 10.0 5.0 23.0 89.0
2 1 2 3
the sorted column matrix is1 89.0 23.0 10.0 5.0
the column matrix 24.0 23.0 6.0 8.0
3 1 2 3
the sorted column matrix is2 24.0 23.0 8.0 6.0
for (int j = i; j < arraytosort.length; j++) {
start i
in second loop
Comments
Post a Comment