- package com.heima.bubble;
- public class Demo2_SelectSort {
- /**
- * 选择排序
- */
- public static void main(String[] args) {
- int[] arr = {5,7,9,2,1,3,5,76,8};
- for (int i = 0; i < arr.length-1; i++) {
- for (int j = i + 1; j < arr.length; j++) {
- if(arr[i]>arr[j]) {
- arr[i]=arr[i]^arr[j];
- arr[j]=arr[i]^arr[j];
- arr[i]=arr[i]^arr[j];
- }
- }
- }
- for (int i = 0; i < arr.length; i++) {
- System.out.print(arr[i]+" ");
- }
- }
- }
复制代码 |
|