@@ -0,0 +1,2481 @@
+/**%0A * Copyright %C2%A9 2014  Mattias Andr%C3%A9e (maandree@member.fsf.org)%0A * %0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Affero General Public License for more details.%0A * %0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage algorithms.arrays;%0A%0Aimport java.util.*;%0A%0A%0A/**%0A * Class for checking whether an array is sorted and in which order it is sorted%0A */%0Apublic class Sorted%0A%7B%0A    /**%0A     * The array is not sorted%0A     */%0A    public static final int UNORDERED = 0;%0A    %0A    /**%0A     * The array is sorted in ascending (normal) order%0A     */%0A    public static final int ASCENDING_ORDER = 1;%0A    %0A    /**%0A     * The array is sorted in descending (reverse normal) order%0A     */%0A    public static final int DESCENDING_ORDER = 2;%0A    %0A    /**%0A     * All elements in the array are mutually equal or the array contains less than two elements.%3Cbr%3E%0A     * This is the bitwise OR of %7B@link ASCENDING_ORDER%7D and %7B@link DESCENDING_ORDER%7D.%0A     */%0A    public static final int FLAT = 3;%0A    %0A    %0A    %0A%C2%A3%3Efor T in boolean char byte short int long float double T T+; do . src/comparable%0A    /**%0A     * Gets whether an array is sorted and in which order it is sorted%0A     *%0A     * @param   items  The items to check if they are ordered%0A     * @return         %7B@link #UNORDERED%7D, %7B@link #ASCENDING_ORDER%7D, %7B@link #DESCENDING_ORDER%7D or %7B@link #FLAT%7D%0A     */%0A    public static %C2%A3(fun %22int%22 %22isSorted%22 %22$%7BT%7D%5B%5D items%22)%0A    %7B%0A%09if (items.length == 0)%0A%09    return FLAT;%0A        %0A%09%C2%A3%7BT%7D last = items%5B0%5D, cur;%0A%09int order = FLAT;%0A        %0A%09for (int i = 1, n = items.length; i %3C n; i++)%0A%09%7B%0A%09    cur = items%5Bi%5D;%0A%09    if (%C2%A3(less %22last%22 %22cur%22))%0A%09    %7B%0A%09%09if (order == FLAT)%0A%09%09    order = ASCENDING_ORDER;%0A%09%09else if (order == DESCENDING_ORDER)%0A%09%09    return UNORDERED;%0A%09    %7D%0A%09    else if (%C2%A3(greater %22last%22 %22cur%22))%0A%09%09if (order == FLAT)%0A%09%09    order = DESCENDING_ORDER;%0A%09%09else if (order == ASCENDING_ORDER)%0A%09%09    return UNORDERED;%0A%09    last = cur;%0A%09%7D%0A        %0A%09return order;%0A    %7D%0A%C2%A3%3Edone%0A%7D%0A%0A

add sorted