Posts

Showing posts with the label selection sorting descending order

selection sorting descending order

Image
Data structure in java sorting in data structure selection sorting    selection sorting ascending order      Example program selection sorting ascending order package sortingInJava; public class selectionSortingDescending { public int max(int[] arr,int from) { int maxValue=arr[from]; int maxVIndex=from; for(int i=from+1;i<arr.length;i++) { if(maxValue<arr[i]) { maxValue=arr[i]; maxVIndex=i; } } return maxVIndex; } public int[] selectionSortedArray(int[] arr) { for(int i=0;i<arr.length;i++) { int maxVIndex=this.max(arr, i); int temp=arr[i]; arr[i]=arr[maxVIndex]; arr[maxVIndex]=temp; } return arr; } public static void main(String arg[]) { int[] arr={510,222,3,422,110}; arr=new selectionSorting().selectionSortedArray(arr); for(int i:arr) System.out.println(i); } } output insertion sorting insertion sorting with descending order insertion sorting with ascending order selection sorti...