- //maopao
- public class haha
- {
- public static void main(String[]args)
- {
- int []arr={3,1,6,4,8,2,9,65,1,24,61};
- maopao(arr);
- dayin(arr);
- }
- public static void maopao(int [] arr)
- {
- for (int x=0;x<arr.length-1 ;x++ )
- {
- int temp=0;
- for (int y=0; y<arr.length-x-1;y++ )
- {
- if (arr[temp]<arr[y+1])
- {temp=y+1;
-
- }
- }
- zhihuan(arr,temp,arr.length-x-1);
- }
- }
- public static void dayin(int[]arr)
- {
- for (int x=0;x<arr.length ;x++ )
- {
- System.out.println(arr[x]);
- }
- }
- public static void zhihuan(int[]arr,int x,int y)
- {
- arr[x]=arr[x]^arr[y];
- arr[y]=arr[x]^arr[y];
- arr[x]=arr[x]^arr[y];
- }
- }
复制代码 原理就是冒泡排序,但是打印的时候会有0出现 |