I think i finally understood what you want.
Code:
public class Test {
public static void main(String[] args) {
char [] a=new char[10];
a[0]='a';
a[1]='b';
a[2]='c';
a[3]='c';
a[4]='c';
a[5]='d';
int newSize=deleteRepeats(a, 3);
System.out.println(newSize);
}
public static int deleteRepeats(char[]array, int size){
int count=0;
char arrayTemp[] = new char[array.length];
// lets make a copy of the array, so we won't change it.
for(int i=0; i<size; i++){
arrayTemp[i] = array[i];
}
//clear all slots with repeating chars
for(int i=0; i<size; i++){
for(int j=i+1; j<size; j++){
if(arrayTemp[j] == arrayTemp[i]) arrayTemp[j] = 0;
}
}
//lets "cut" the caps inside of the array
char [] a=new char[arrayTemp.length];
int charcount=0;
for(int i=0; i<size; i++){
if(arrayTemp[i] != 0){
a[charcount] = arrayTemp[i];
charcount++;
}
}
for(int i=0; i<arrayTemp.length; i++){
arrayTemp[i] = a[i];
}
// count the chars left
for(int i=0; i<size; i++){
if(arrayTemp[i] != 0 ) count++;
}
return count;
}
}
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum