int unique(int *array, int number) //sorted array
{
int k = 0;
for (int i = 1; i < n; i++) {
if (a[k] != a[i]) { //comparing the first 2 unequal numbers
a[k+1] = a[i]; //shifting to the left if distinct
k++;
}
}
return (k+1); //return the last index of new array i.e. the number of distinct elements
}
Algorithm to remove duplicates from a sorted array
30 Friday Jul 2010
Posted in Algos