|
-
February 7th, 2010, 11:54 AM
#14
Re: Compacting an array in C++
bool bRemoveDuplicates(int array[], int iSize){
if(iSize <1)
return false;
if(array == NULL)
return false;
if(iSize == 1)
return true;
int left_comp = 0;
int right_comp = 1;
bool start_move = false;
int hole = iSize;
for(; right_comp <iSize;right_comp++,left_comp++){
if(array[left_comp] == array[right_comp]){
if(!start_move){
start_move = true;
hole = right_comp;
}
}
else if(start_move){
array[hole++] = array[right_comp];
}
}
for(;hole<iSize;hole++){
array[hole] = 0;
}
return true;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|