/ Published in: Java
This is a Bubble Sorter in java
(was a pain in the ass to get right)
you can change the sorting style from ascending to descending order
by changing the line
if(vals[d+1] < vals[d])
to
if(vals[d+1] > vals[d])
(was a pain in the ass to get right)
you can change the sorting style from ascending to descending order
by changing the line
if(vals[d+1] < vals[d])
to
if(vals[d+1] > vals[d])
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static double[] SortArray(double[] vals) { double temp=0; double ret[]= new double[vals.length]; for(int c=0;c < vals.length;c++) { for(int d=0;d < vals.length - 1;d++) { if(vals[d+1] < vals[d]) { temp = vals[d]; vals[d] = vals[d + 1]; vals[d + 1] = temp; } } } ret = vals; return ret; }