selection sorting descending order

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

Comments

Popular posts from this blog

delete at last position in java

Create a class named Movie that can be used with your video rental business in java

A publishing company that markets both book and audio-cassette in java. (Solution)