选择排序和运用的场景 java语言

mac2022-06-30  121

选择排序:不稳定

适用于:数据量不大,并且对稳定性没有要求的情况。

 

public class SelexctSort { public static void main(String[] args) { Scanner in=new Scanner(System.in); char[] s=in.nextLine().toCharArray(); in.close(); selectSort(s); System.out.println(Arrays.toString(s));} public static void selectSort(char[] a) { for(int i=0;i<a.length-1;i++) { char min=a[i]; for(int j=i+1;j<a.length;j++) { if(a[j]<min) { char temp=min; min=a[j]; a[j]=temp; } } a[i]=min; } }

 

}

 

转载于:https://www.cnblogs.com/sgbe/p/10760629.html

最新回复(0)