亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sorter.java

?? 164個完整的Java代碼,資源比較大
?? JAVA
字號:
/* * Copyright (c) 2000 David Flanagan.  All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */package com.davidflanagan.examples.classes;// These are some classes we need for internationalized string sortingimport java.text.Collator; import java.text.CollationKey;import java.util.Locale;/** * This class defines a bunch of static methods for efficiently sorting * arrays of Strings or other objects.  It also defines two interfaces that * provide two different ways of comparing objects to be sorted. **/public class Sorter {    /**     * This interface defines the compare() method used to compare two objects.     * To sort objects of a given type, you must provide a Comparer     * object with a compare() method that orders those objects as desired     **/    public static interface Comparer {        /**	 * Compare objects, return a value that indicates their relative order:	 * if (a > b) return > 0; 	 * if (a == b) return 0;	 * if (a < b) return < 0. 	 **/        public int compare(Object a, Object b);    }    /**     * This is an alternative interface that can be used to order objects.  If     * a class implements this Comparable interface, then any two instances of     * that class can be directly compared by invoking the compareTo() method.     **/    public static interface Comparable {        /** 	 * Compare objects, return a value that indicates their relative order:	 * if (this > other) return > 0	 * if (this == other) return 0	 * if (this < other) return < 0	 **/        public int compareTo(Object other);    }    /**     * This is an internal Comparer object (created with an anonymous class)     * that compares two ASCII strings.       * It is used in the sortAscii methods below.     **/    private static Comparer ascii_comparer = new Comparer() {	    public int compare(Object a, Object b) {		return ((String)a).compareTo((String)b);	    }	};        /**     * This is another internal Comparer object.  It is used to compare two     * Comparable objects.  It is used by the sort() methods below that take     * Comparable objects as arguments instead of arbitrary objects     **/    private static Comparer comparable_comparer = new Comparer() {	    public int compare(Object a, Object b) {		return ((Comparable)a).compareTo(b);	    }	};        /** Sort an array of ASCII strings into ascending order */    public static void sortAscii(String[] a) {        // Note use of the ascii_comparer object        sort(a, null, 0, a.length-1, true, ascii_comparer);     }        /**      * Sort a portion of an array of ASCII strings into ascending or descending     * order, depending on the argument up     **/    public static void sortAscii(String[] a, int from, int to, boolean up) {        // Note use of the ascii_comparer object        sort(a, null, from, to, up, ascii_comparer);    }        /** Sort an array of ASCII strings into ascending order, ignoring case */    public static void sortAsciiIgnoreCase(String[] a) {        sortAsciiIgnoreCase(a, 0, a.length-1, true);    }        /**     * Sort an portion of an array of ASCII strings, ignoring case.  Sort into     * ascending order if up is true, otherwise sort into descending order.     **/    public static void sortAsciiIgnoreCase(String[] a, int from, int to,					   boolean up) {        if ((a == null) || (a.length < 2)) return;        // Create a secondary array of strings that contains lowercase versions        // of all the specified strings.         String b[] = new String[a.length];        for(int i = 0; i < a.length; i++) b[i] = a[i].toLowerCase();        // Sort that secondary array, and rearrange the original array         // in exactly the same way, resulting in a case-insensitive sort.        // Note the use of the ascii_comparer object        sort(b, a, from, to, up, ascii_comparer);    }        /**      * Sort an array of strings into ascending order, using the correct     * collation order for the default locale     **/    public static void sort(String[] a) {        sort(a, 0, a.length-1, true, false, null);    }        /**     * Sort a portion of an array of strings, using the collation order of     * the default locale.   If up is true, sort ascending, otherwise, sort     * descending.  If ignorecase is true, ignore the capitalization of letters     **/    public static void sort(String[] a, int from, int to, 			    boolean up, boolean ignorecase) {        sort(a, from, to, up, ignorecase, null);    }        /**     * Sort a portion of an array of strings, using the collation order of     * the specified locale.   If up is true, sort ascending, otherwise, sort     * descending.  If ignorecase is true, ignore the capitalization of letters     **/    public static void sort(String[] a, int from, int to, 			    boolean up, boolean ignorecase, 			    Locale locale) {        // Don't sort if we don't have to        if ((a == null) || (a.length < 2)) return;	        // The java.text.Collator object does internationalized string compares        // Create one for the specified, or the default locale.        Collator c;        if (locale == null) c = Collator.getInstance();        else c = Collator.getInstance(locale);	        // Specify whether or not case should be considered in the sort.        // Note: this option does not seem to work correctly in JDK 1.1.1        // using the default American English locale.        if (ignorecase) c.setStrength(Collator.SECONDARY);	        // Use the Collator object to create an array of CollationKey objects         // that correspond to each of the strings.          // Comparing CollationKeys is much quicker than comparing Strings        CollationKey[] b = new CollationKey[a.length];        for(int i = 0; i < a.length; i++) b[i] = c.getCollationKey(a[i]);        // Now define a Comparer object to compare collation keys, using an        // anonymous class.        Comparer comp =  new Comparer() {		public int compare(Object a, Object b) {		    return ((CollationKey)a).compareTo((CollationKey)b);		}	    };	        // Finally, sort the array of CollationKey objects, rearranging the         // original array of strings in exactly the same way.        sort(b, a, from, to, up, comp);    }        /** Sort an array of Comparable objects into ascending order */    public static void sort(Comparable[] a) {        sort(a, null, 0, a.length-1, true);    }        /**     * Sort a portion of an array of Comparable objects.  If up is true,     * sort into ascending order, otherwise sort into descending order.     **/    public static void sort(Comparable[] a, int from, int to, boolean up) {        sort(a, null, from, to, up, comparable_comparer);    }        /**     * Sort a portion of array a of Comparable objects.  If up is true,     * sort into ascending order, otherwise sort into descending order.     * Re-arrange the array b in exactly the same way as a.     **/    public static void sort(Comparable[] a, Object[] b, 			    int from, int to, boolean up) {        sort(a, b, from, to, up, comparable_comparer);    }        /**     * Sort an array of arbitrary objects into ascending order, using the      * comparison defined by the Comparer object c     **/    public static void sort(Object[] a, Comparer c) {        sort(a, null, 0, a.length-1, true, c);    }        /**     * Sort a portion of an array of objects, using the comparison defined by     * the Comparer object c.  If up is true, sort into ascending order,      * otherwise sort into descending order.     **/    public static void sort(Object[] a, int from, int to, boolean up,			    Comparer c)    {        sort(a, null, from, to, up, c);    }        /**     * This is the main sort() routine. It performs a quicksort on the elements     * of array a between the element from and the element to.  The up argument     * specifies whether the elements should be sorted into ascending (true) or     * descending (false) order.  The Comparer argument c is used to perform     * comparisons between elements of the array.  The elements of the array b     * are reordered in exactly the same way as the elements of array a are.     **/    public static void sort(Object[] a, Object[] b, 			    int from, int to, 			    boolean up, Comparer c)    {        // If there is nothing to sort, return        if ((a == null) || (a.length < 2)) return;	        // This is the basic quicksort algorithm, stripped of frills that can        // make it faster but even more confusing than it already is.  You        // should understand what the code does, but don't have to understand        // just why it is guaranteed to sort the array...        // Note the use of the compare() method of the Comparer object.        int i = from, j = to;        Object center = a[(from + to) / 2];        do {            if (up) {  // an ascending sort                while((i < to)&& (c.compare(center, a[i]) > 0)) i++;                while((j > from)&& (c.compare(center, a[j]) < 0)) j--;            } else {   // a descending sort                while((i < to)&& (c.compare(center, a[i]) < 0)) i++;                while((j > from)&& (c.compare(center, a[j]) > 0)) j--;            }            if (i < j) {                 Object tmp = a[i];  a[i] = a[j];  a[j] = tmp; // swap elements                if (b != null) { tmp = b[i]; b[i] = b[j]; b[j] = tmp; } // swap            }            if (i <= j) { i++; j--; }        } while(i <= j);        if (from < j) sort(a, b, from, j, up, c); // recursively sort the rest        if (i < to) sort(a, b, i, to, up, c);    }    /**     * This nested class defines a test program that demonstrates several     * ways to use the Sorter class to sort ComplexNumber objects     **/    public static class Test {        /**	 * This subclass of ComplexNumber implements the Comparable interface	 * and defines a compareTo() method for comparing complex numbers.	 * It compares numbers based on their magnitude. I.e. on their distance	 * from the origin.	 **/        static class SortableComplexNumber extends ComplexNumber 	    implements Sorter.Comparable {            public SortableComplexNumber(double x, double y) { super(x, y); }            public int compareTo(Object other) {                return sign(this.magnitude()-((ComplexNumber)other).magnitude());            }        }	        /** A a test program that sorts complex numbers in various ways. */        public static void main(String[] args) {            // Define an array of SortableComplexNumber objects.  Initialize it            // to contain random complex numbers.            SortableComplexNumber[] a = new SortableComplexNumber[5];            for(int i = 0; i < a.length; i++)                a[i] = new SortableComplexNumber(Math.random()*10,						 Math.random()*10);	                // Now sort it using the SortableComplexNumber compareTo() method,             // which sorts by magnitude, and print the results out.            System.out.println("Sorted by magnitude:");            Sorter.sort(a);            for(int i = 0; i < a.length; i++) System.out.println(a[i]);	                // Sort the complex numbers again, using a Comparer object that            // compares them based on the sum of their real and imaginary parts            System.out.println("Sorted by sum of real and imaginary parts:");            Sorter.sort(a, new Sorter.Comparer() {		    public int compare(Object a, Object b) {			ComplexNumber i = (ComplexNumber)a;			ComplexNumber j = (ComplexNumber)b;			return sign((i.real() + i.imaginary()) - 				    (j.real() + j.imaginary()));		    }		});            for(int i = 0; i < a.length; i++) System.out.println(a[i]);            // Sort them again using a Comparer object that compares their real            // parts, and then their imaginary parts            System.out.println("Sorted descending by real, then imaginary:");            Sorter.sort(a, 0, a.length-1, false, new Sorter.Comparer() {		    public int compare(Object a, Object b) {			ComplexNumber i = (ComplexNumber) a;			ComplexNumber j = (ComplexNumber) b;			double result = i.real() - j.real();			if (result == 0) result = i.imaginary()-j.imaginary();			return sign(result);		    }		});            for(int i = 0; i < a.length; i++) System.out.println(a[i]);        }        /** This is a convenience routine used by comparison routines */        public static int sign(double x) {            if (x > 0) return 1;            else if (x < 0) return -1;            else return 0;        }    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品福利一区二区三区蜜桃| 激情综合亚洲精品| 久久久99精品免费观看不卡| 制服丝袜国产精品| 69p69国产精品| 6080yy午夜一二三区久久| 欧美日韩亚洲综合在线| 欧美日韩五月天| 欧美久久婷婷综合色| 欧美精品aⅴ在线视频| 欧美日韩免费视频| 精品日韩一区二区三区 | 国产精品美日韩| 久久久久久久综合日本| 欧美国产一区二区| 国产精品网站一区| 亚洲精品视频在线观看免费| 亚洲免费高清视频在线| 午夜视频一区二区三区| 奇米影视一区二区三区小说| 男男视频亚洲欧美| 国产成人精品免费网站| 成人精品小蝌蚪| 91美女在线看| 日韩亚洲欧美一区| 久久久99精品久久| 蜜臀av一区二区在线免费观看| 日韩激情一二三区| 狠狠色丁香久久婷婷综合丁香| 国产超碰在线一区| 日本福利一区二区| 国产精品久久久久影院老司| 欧美经典三级视频一区二区三区| 国产精品视频线看| 亚洲一二三区在线观看| 国产精一区二区三区| 欧美夫妻性生活| 日韩精品一区在线| 色婷婷狠狠综合| 日韩美女一区二区三区| 日韩美女视频19| 久久精品国产精品亚洲综合| 成人aa视频在线观看| 欧美一区二区精品在线| 中文字幕一区二区在线观看| 视频一区二区欧美| 色综合久久六月婷婷中文字幕| 日韩女优av电影在线观看| 国产精品久久久久影视| 美女在线一区二区| 欧美在线一二三| 国产精品久久久久影院老司 | 亚洲一区二区欧美| 国产精品1024| 欧美一级高清片| 夜夜夜精品看看| 久久久久久久久久美女| 69堂国产成人免费视频| 国产精品女人毛片| 精品一区二区久久久| 欧美无人高清视频在线观看| 国产精品视频在线看| 国产在线一区二区综合免费视频| 欧美又粗又大又爽| 亚洲欧美电影院| 成人va在线观看| 国产日产精品1区| 国产美女精品人人做人人爽| 91麻豆精品国产综合久久久久久| 一区二区三区在线免费视频| 成人av在线影院| 国产亚洲成aⅴ人片在线观看| 日本中文字幕一区二区有限公司| 欧美日韩精品一区二区天天拍小说| 亚洲欧洲一区二区在线播放| 成人综合婷婷国产精品久久免费| 精品国产一二三| 黄一区二区三区| 精品少妇一区二区三区日产乱码| 日韩精品一级中文字幕精品视频免费观看 | 日韩精品一级二级| 日本一区二区免费在线观看视频| 蜜臀久久久久久久| 91精品国产综合久久精品app| 偷窥少妇高潮呻吟av久久免费| 欧美日韩在线三级| 轻轻草成人在线| 欧美不卡视频一区| 国产精品综合在线视频| 日本一区二区三区国色天香| av在线综合网| 亚洲第一狼人社区| 欧美剧情片在线观看| 久久爱www久久做| 国产精品女上位| 日本韩国欧美国产| 日本欧美加勒比视频| 欧美视频在线观看一区| 亚洲视频你懂的| 亚洲欧洲日产国产综合网| 国产精品自拍网站| 中文字幕一区日韩精品欧美| 一本到不卡精品视频在线观看| 亚洲福利视频一区二区| 日韩视频123| 成人h精品动漫一区二区三区| 亚洲女人的天堂| 日韩一级黄色片| 成人涩涩免费视频| 同产精品九九九| 国产欧美中文在线| 欧美日韩一区三区| 国产麻豆精品在线观看| 亚洲国产一区视频| 久久婷婷综合激情| 欧美丝袜自拍制服另类| 国产麻豆精品视频| 亚洲va国产天堂va久久en| 久久亚洲二区三区| 欧美最猛性xxxxx直播| 国产麻豆欧美日韩一区| 亚洲成人资源网| 亚洲天天做日日做天天谢日日欢| 69久久夜色精品国产69蝌蚪网| 成人福利在线看| 久久精品国产网站| 午夜在线成人av| 亚洲欧洲成人精品av97| 久久新电视剧免费观看| 在线观看91av| 在线视频一区二区三区| 风流少妇一区二区| 久久成人免费网| 亚洲妇女屁股眼交7| 中文字幕一区二| 国产欧美日韩另类一区| 欧美va日韩va| 欧美精品1区2区| 欧美性猛片aaaaaaa做受| 97国产一区二区| 成人激情综合网站| 国产精品资源在线看| 久久精品理论片| 日韩和欧美一区二区| 亚洲国产乱码最新视频| 亚洲精品欧美在线| 国产精品成人免费精品自在线观看| 久久色在线视频| 欧美成人女星排名| 欧美岛国在线观看| 日韩三级视频中文字幕| 7777精品伊人久久久大香线蕉最新版| 色妹子一区二区| 91成人网在线| 欧美性受xxxx黑人xyx性爽| 在线观看日韩av先锋影音电影院| 91在线码无精品| 91蝌蚪porny九色| 在线精品视频免费观看| 欧美性做爰猛烈叫床潮| 欧美日韩你懂得| 欧美一区二区三区在线观看视频 | 五月天欧美精品| 偷拍一区二区三区四区| 丝袜诱惑制服诱惑色一区在线观看 | 亚洲午夜免费视频| 午夜精品福利在线| 国产成人精品亚洲777人妖| 激情av综合网| 久久99精品久久久| 国产精品一二三在| fc2成人免费人成在线观看播放| 国产91在线观看丝袜| www.色综合.com| 欧美性感一区二区三区| 日韩一区二区三区免费看| 精品国产一区二区三区久久影院| 久久久亚洲精品一区二区三区 | 中文字幕不卡一区| 亚洲人成精品久久久久| 亚洲欧美日韩在线不卡| 在线视频国内自拍亚洲视频| 日韩精品自拍偷拍| jlzzjlzz欧美大全| 色哟哟精品一区| 欧美剧情电影在线观看完整版免费励志电影| 欧美美女黄视频| 国产亚洲欧美在线| 一区二区欧美精品| 久久 天天综合| 94-欧美-setu| 日韩亚洲欧美中文三级| 国产精品久久看| 天天免费综合色| 成人网男人的天堂| 欧美美女激情18p| 国产精品进线69影院| 久久国产成人午夜av影院| 99在线精品一区二区三区| 欧美一级在线观看|