Java Array Sort difference(int[] sorted1, int[] sorted2)

Here you can find the source of difference(int[] sorted1, int[] sorted2)

Description

difference

License

Open Source License

Declaration

public static int[] difference(int[] sorted1, int[] sorted2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static int[] difference(int[] sorted1, int[] sorted2) {
        int[] result = new int[sorted1.length];
        int i = 0, j = 0, k = 0;

        while (i < sorted1.length && j < sorted2.length) {
            if (sorted1[i] < sorted2[j]) {
                result[k++] = sorted1[i];
                i++;/* ww w .  j  a v  a  2  s . c  o  m*/
            } else if (sorted1[i] > sorted2[j]) {
                j++;
            } else {
                i++;
                j++;
            }
        }
        for (; i < sorted1.length; i++)
            result[k++] = sorted1[i];
        return Arrays.copyOf(result, k);
    }
}

Related

  1. copyAndSort(T[] builtinFunctions)
  2. copySortArray(String[] values)
  3. countingSort(int[] a, int low, int high)
  4. countingSort(int[] array, int low, int high)
  5. deltaMetricToSortedIndicies( final double[][] deltaMetric)
  6. extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)
  7. getLeftIndex(float[] sorted, float value)
  8. getMedianIndex(float[] sorted, float value)
  9. getNewSortedIntArray(int[] codePointArray)