思路都再注释里~直接上代码
import java.util.Arrays;
public class BasicSort {
public static void bubbleSort(int n[])
{
for(int i=1;i<n.length;i++)
for(int j=0;j<i;j++)
if(n[j]>n[i])
{
int temp=n[i];
n[i]=n[j];
n[j]=temp;
}
}
public static void selectionSort(int n[])
{
int max_index=0;
int temp=0;
for(int i=n.length-1;i>=0;i--)
{
for(int j=0;j<=i;j++)
if(n[max_index]<n[j])
{
max_index=j;
}
temp=n[i];
n[i]=n[max_index];
n[max_index]=temp;
max_index=0;
}
}
public static void main(String[] args) {
int n[]= {9,23,54,1,2,3,36,12,59,9,67,81};
bubbleSort(n);
System.out.println(Arrays.toString(n));
}
}