package com.lovecoding.day12.ex02;

import java.util.Comparator;

public class ArrayTools {
    public static void sort(Employee[] arr){
        //排序
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length-i; j++) {
                //调换
                if( arr[j].compareTo(arr[j + 1]) > 0 ){
                    Employee temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }

    //Comparator 定义排序规则
    public static void sort(Employee[] arr, Comparator c){
        //排序
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < arr.length-i; j++) {
                //调换
                if( c.compare(arr[j],arr[j+1]) > 0 ){
                    Employee temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }

    public static void print(Object[] arr){
        for (Object o : arr) {
            System.out.println(o);
        }
    }
}
