关于Itti的MATLAB算法

关于Itti的MATLAB算法,第1张

实现一个Comparator就可以了

代码如下:

import java.util.Arrays

import java.util.Comparator

public class ChineseSort {

    public static void main(String[] args) {

        String[] list = {

                "丙方",

                "乙方",

                "甲方",

                "辛方",

                "戊方", }

        System.out.println("排序前: " + Arrays.toString(list))

        sort(list)

        System.out.println("排序后: " + Arrays.toString(list))

    }

    public static void sort(String[] args) {

        Comparator<String> comparator = new Comparator<String>() {

            @Override

            public int compare(String o1, String o2) {

                return getIndex(o1) - getIndex(o2)

            }

        }

        Arrays.sort(args, comparator)

    }

    private static int getIndex(String s) {

        for (int i = 0 i < DEFAULT_ARRAY.length i++) {

            if (s.equals(DEFAULT_ARRAY[i])) {

                return i

            }

        }

        throw new RuntimeException("输入文字错误")

    }

    private static final String[] DEFAULT_ARRAY = {

                                                        "甲方",

                                                        "乙方",

                                                        "丙方",

                                        漏猜没   兆姿             "丁方",

                返纳                                        "戊方",

                                                        "己方",

                                                        "庚方",

                                                        "辛方",

                                                        "壬方",

                                                        "癸方" }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12516289.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存