package com;
import java.util.Arrays;
public class SortDemo {
public static void main(String[] args) {
int[] ary= {2,9,22,3,4,5};
bubbleSort(ary);
System.out.println(Arrays.toString(ary));
selectSort(ary);
System.out.println(Arrays.toString(ary));
}
public static void bubbleSort(int[] ary) {
for(int i=0;i<ary.length-1;i++) {
for(int j=0;j<ary.length-1-i;j++) {
if(ary[j]<ary[j+1]) {
int temp=ary[j];
ary[j]=ary[j+1];
ary[j+1]=temp;
}
}
}
}
public static void selectSort(int[] ary) {
for(int i=0;i<ary.length-1;i++) {
for(int j=i+1;j<=ary.length-1;j++) {
if(ary[i]<ary[j]) {
int temp=ary[i];
ary[i]=ary[j];
ary[j]=temp;
}
}
}
}
}