Here you can find the source of getSortedDistinct(int[] values)
Parameter | Description |
---|---|
values | input array (this method will quickSort this array) |
public static int[] getSortedDistinct(int[] values)
//package com.java2s; /*//from www. j a v a 2s. co m * Redberry: symbolic tensor computations. * * Copyright (c) 2010-2013: * Stanislav Poslavsky <stvlpos@mail.ru> * Bolotin Dmitriy <bolotin.dmitriy@gmail.com> * * This file is part of Redberry. * * Redberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Redberry is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Redberry. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Arrays; public class Main { /** * Sort array & return array with removed repetitive values. * * @param values input array (this method will quickSort this array) * * @return sorted array of distinct values */ public static int[] getSortedDistinct(int[] values) { if (values.length == 0) return values; Arrays.sort(values); int shift = 0; int i = 0; while (i + shift + 1 < values.length) if (values[i + shift] == values[i + shift + 1]) ++shift; else { values[i] = values[i + shift]; ++i; } values[i] = values[i + shift]; return Arrays.copyOf(values, i + 1); } }