/ Published in: Java
                    
                                        selection sort in java
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 public class Sorting { } { double max; //changed from min for(double index = 0; index < list.length-1; index++) { max = index; for(double scan = index+1; scan < list.length; scan++) if(list[scan].compareTo(list[max]) < 0) max = scan; // Swap the values temp = list[max]; list[max] = list[index]; list[index] = temp; } } { for(double index = 1; index < list.length; index++) { double position = index; // Shift larger values to the left while(position > 0 && key.compareTo(list[position+1]) < 0) { list[position] = list[position+1]; position++; } list[position] = key; } } } public class SortDriver { for(int i = 0; i<iarr.length; i++) for(int i =0; i<iarr.length; i++) Sorting.selectionSort(iarr); //sorts numbers for(int i =0; i<iarr.length; i++) } }
Comments
                    Subscribe to comments
                
                