亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
一本一本久久a久久精品综合麻豆 一本一道波多野结衣一区二区 | 国产精品一区二区在线播放| 国产女人aaa级久久久级| 99国产精品久久久久久久久久| 一区二区激情小说| 精品成人佐山爱一区二区| 色婷婷av一区二区三区之一色屋| 亚洲一级二级三级在线免费观看| 精品国产自在久精品国产| 色综合久久中文字幕综合网| 国产91精品入口| 国产精品久久久久久久久图文区| 欧美巨大另类极品videosbest| 成人av电影在线播放| 日韩高清中文字幕一区| 久久久国际精品| 欧美精品乱人伦久久久久久| 国产精品一级黄| 国产精品国产a级| 久久综合九色综合欧美98| 日本精品一级二级| 国产毛片精品一区| 有码一区二区三区| 国产欧美一区二区精品仙草咪| 欧美一区二区精美| 日本道精品一区二区三区| 美女视频第一区二区三区免费观看网站| 亚洲欧美另类图片小说| 久久久久国产成人精品亚洲午夜| 欧美一区二区私人影院日本| 色88888久久久久久影院野外| 国产麻豆91精品| 国产精品白丝jk白祙喷水网站| 亚洲午夜免费视频| 亚洲第一激情av| 亚洲欧美日韩一区二区三区在线观看| 精品国产凹凸成av人网站| 欧美日高清视频| 在线免费观看视频一区| 国产精品一区二区在线看| 蜜乳av一区二区| 麻豆国产精品一区二区三区| 亚洲图片自拍偷拍| 中文字幕av一区 二区| 国产精品三级在线观看| 国产调教视频一区| 国产精品黄色在线观看| 欧美经典三级视频一区二区三区| 欧美日韩一区二区在线视频| 精品视频在线视频| 欧美日韩精品免费观看视频| 717成人午夜免费福利电影| 色伊人久久综合中文字幕| 91性感美女视频| 色成年激情久久综合| 91蜜桃网址入口| 91原创在线视频| 91视频www| 色老汉一区二区三区| 丁香婷婷深情五月亚洲| 成人在线视频一区二区| 日本乱码高清不卡字幕| 在线免费观看视频一区| 日韩一区二区免费在线观看| 精品裸体舞一区二区三区| 久久综合国产精品| 欧美激情一区在线观看| 中文字幕亚洲不卡| 综合久久久久久久| 亚洲一区二区在线播放相泽| 国产精品高潮久久久久无| 婷婷成人激情在线网| 久久综合综合久久综合| 成人黄色av电影| 91麻豆文化传媒在线观看| 色综合色综合色综合色综合色综合 | 亚洲一区视频在线观看视频| 国产精品国产三级国产普通话蜜臀| 日本一区二区三区dvd视频在线| 欧美激情在线观看视频免费| 亚洲男同性恋视频| 亚洲不卡一区二区三区| 免费久久99精品国产| 91一区在线观看| 欧美日韩午夜在线视频| 欧美成人官网二区| 国产精品久久久久久久久久久免费看| 亚洲欧美色图小说| 久久99精品久久久久久国产越南| 国产美女一区二区三区| 91久久精品一区二区三区| 一本久久精品一区二区| 日本韩国一区二区| 久久精品一区二区三区不卡| 日韩一区日韩二区| 极品少妇xxxx精品少妇| 91婷婷韩国欧美一区二区| 精品国产乱码久久久久久浪潮 | 日韩一本二本av| 国产亚洲欧美激情| 亚洲美女区一区| 色国产综合视频| 国内精品久久久久影院色| 五月激情综合网| 日韩一级片在线播放| 亚洲成人1区2区| 欧美疯狂做受xxxx富婆| 制服.丝袜.亚洲.另类.中文| 国产精品每日更新| 欧美久久久久久蜜桃| 麻豆传媒一区二区三区| 欧美韩国日本综合| 韩国av一区二区三区四区 | 一区二区三区久久久| 亚洲欧美一区二区三区极速播放 | 夜夜精品浪潮av一区二区三区| 亚洲女爱视频在线| 国产乱码精品一区二区三区忘忧草| 欧美日韩国产另类一区| 日韩高清一级片| 日韩午夜激情电影| 国产一区二区网址| 日韩欧美一区二区久久婷婷| 亚洲伦理在线精品| 在线成人av网站| 同产精品九九九| 欧美精品在线视频| 亚洲18影院在线观看| a亚洲天堂av| 国产精品久久久久久久久免费丝袜 | 日韩三级中文字幕| 亚洲国产激情av| 国产成人在线视频免费播放| 色综合久久中文综合久久97 | 日韩免费观看高清完整版| 一区二区三区不卡在线观看 | 欧美丝袜自拍制服另类| 久久99精品国产麻豆婷婷洗澡| 777色狠狠一区二区三区| 日韩av电影免费观看高清完整版在线观看| 91国产丝袜在线播放| 国产精品亲子伦对白| 国产精品亚洲一区二区三区在线 | 国产一区二区三区在线看麻豆| 91国产成人在线| 国产视频一区不卡| 国产99久久久久久免费看农村| 久久精品夜色噜噜亚洲aⅴ| 欧美这里有精品| 久久99精品久久久久久久久久久久| 美女网站色91| 日本韩国精品在线| 亚洲欧洲美洲综合色网| 一本久道久久综合中文字幕 | 一区免费观看视频| 91丨国产丨九色丨pron| 国产精品理论片在线观看| 91在线小视频| 亚洲女同ⅹxx女同tv| 国产福利不卡视频| 中文字幕亚洲电影| 91一区二区在线| 亚洲综合成人在线| 91在线观看成人| 亚洲午夜精品网| 欧美一区三区四区| 国产盗摄精品一区二区三区在线| 国产女主播视频一区二区| 色综合天天性综合| 亚洲国产三级在线| 91亚洲精品久久久蜜桃网站| 日韩国产精品久久久| 精品久久国产97色综合| 99视频国产精品| 亚洲一区二区三区影院| 538prom精品视频线放| 久久av资源网| 日本一区二区三区四区| 欧美日韩二区三区| 久久国内精品自在自线400部| 中文字幕在线免费不卡| 欧美肥妇毛茸茸| 香蕉加勒比综合久久| 国产欧美日韩久久| 欧美中文字幕一二三区视频| 国产一区在线不卡| 亚洲青青青在线视频| 欧美狂野另类xxxxoooo| 国产乱码精品一品二品| 久久久久久黄色| 欧美一区二区三区日韩| 国产白丝网站精品污在线入口| 天天色天天爱天天射综合| 久久综合九色综合97_久久久| 99久久精品国产麻豆演员表| 五月激情六月综合| 日本一区二区不卡视频| 精品免费国产一区二区三区四区| 99精品桃花视频在线观看| 国模无码大尺度一区二区三区|