#include<stdio.h>
unsigned remove_dumped_memory(unsigned *array, unsigned nItem);
int main(){
int i;
unsigned size = 10;
unsigned a[10] = {1,1,2,2,2,3,5,8,8,9};
size = remove_dumped_memory(a, size);
printf("content of array:\n"); for(i = 0; i < size; i++){
}
printf("\narray size: %d\n", size
);
return 0;
}
unsigned remove_dumped_memory(unsigned *array, unsigned nItem){
int cnt=1;
int left = 1, right = nItem-1, mid = (left+right)/2;
unsigned key = array[0];
while(left <= right){
if(key != array[left]){
array[cnt] = array[left];
key = array[left];
left++;
mid = (left+right)/2;
cnt++;
}else{
if(key == array[mid]){
left = mid+1;
}else{
mid = (left+mid)/2;
}
}
}
return cnt;
}
I2luY2x1ZGU8c3RkaW8uaD4KIAp1bnNpZ25lZCByZW1vdmVfZHVtcGVkX21lbW9yeSh1bnNpZ25lZCAqYXJyYXksIHVuc2lnbmVkIG5JdGVtKTsKIAppbnQgbWFpbigpewogICAgICAgIGludCBpOwogICAgICAgIHVuc2lnbmVkIHNpemUgPSAxMDsKICAgICAgICB1bnNpZ25lZCBhWzEwXSA9IHsxLDEsMiwyLDIsMyw1LDgsOCw5fTsKIAogICAgICAgIHNpemUgPSByZW1vdmVfZHVtcGVkX21lbW9yeShhLCBzaXplKTsKIAogICAgICAgIHByaW50ZigiY29udGVudCBvZiBhcnJheTpcbiIpOwogICAgICAgIGZvcihpID0gMDsgaSA8IHNpemU7IGkrKyl7CiAgICAgICAgICAgICAgICBwcmludGYoIiVkICIsIGFbaV0pOwogICAgICAgIH0KICAgICAgICBwcmludGYoIlxuYXJyYXkgc2l6ZTogJWRcbiIsIHNpemUpOwogCiAgICAgICAgcmV0dXJuIDA7Cn0KIAp1bnNpZ25lZCByZW1vdmVfZHVtcGVkX21lbW9yeSh1bnNpZ25lZCAqYXJyYXksIHVuc2lnbmVkIG5JdGVtKXsKICAgICAgICBpbnQgY250PTE7CiAgICAgICAgaW50IGxlZnQgPSAxLCByaWdodCA9IG5JdGVtLTEsIG1pZCA9IChsZWZ0K3JpZ2h0KS8yOwogICAgICAgIHVuc2lnbmVkIGtleSA9IGFycmF5WzBdOwogICAgICAgIAogICAgICAgIHdoaWxlKGxlZnQgPD0gcmlnaHQpewogICAgICAgICAgICAgICAgaWYoa2V5ICE9IGFycmF5W2xlZnRdKXsKICAgICAgICAgICAgICAgICAgICAgICAgYXJyYXlbY250XSA9IGFycmF5W2xlZnRdOwogICAgICAgICAgICAgICAgICAgICAgICBrZXkgPSBhcnJheVtsZWZ0XTsKICAgICAgICAgICAgICAgICAgICAgICAgbGVmdCsrOwoJCQltaWQgPSAobGVmdCtyaWdodCkvMjsKICAgICAgICAgICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoa2V5ID09IGFycmF5W21pZF0pewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlZnQgPSBtaWQrMTsKICAgICAgICAgICAgICAgICAgICAgICAgfWVsc2V7CgkJCQltaWQgPSAobGVmdCttaWQpLzI7CgkJCX0KICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNudDsKfQo=