//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 2.11 on page 43

import schaums.dswj.Arrays;

public class Pr0211
{ private static final int SIZE = 16;
  private static int[] a = new int[SIZE];
  public static void main(String[] args)
  { schaums.dswj.Arrays.load(a,10,8);
    schaums.dswj.Arrays.print(a);
    int[] b = withoutDuplicates(a);
    schaums.dswj.Arrays.print(b);
  }
  private static int[] withoutDuplicates(int[] a)
  { if (a.length<2) return a;  // there are no duplicates
    int x = a[0];  // use this value as a dummy marker
    for (int i=1; i<a.length-1; i++)
      for (int j=i+1; j<a.length; j++)
        if (a[j]==a[i]) a[j] = x;
    int count=0;  // count the duplicates
    for (int i=1; i<a.length; i++)
      if (a[i]==x) ++count;
    if (count==0) return a;  // there are no duplicates
    int[] b = new int[a.length-count];
    b[0] = x;
    int shift=0;
    for (int i=1; i<a.length; i++)
      if (shift>0 && a[i] != x) b[i-shift] = a[i];
      else if (a[i]==x) ++shift;
      else b[i] = a[i];
    return b;
  } 
}