Suppose I have 2 sorted arrays. One of them has the elements to delete from the other. For example
int array1[]={1,2,3,4,5,6,7,8,9,10,11,12,13};
int delete[]={5,9,12};
How should I delete the elements indicated in the delete array from array1 and shift the rest in array1 efficiently?
I don't want to go over all the elements of array1 since some of them will be unchanged. So I figured starting from
int j,i=0,n=0;
for(j=delete[i+n];j<delete[i+1+n];j++){
array1[i-n]=array1[i+1-n];
n++;
}
But I couldn't quite figure out how to do it right. Any ideas?
language-agnostic.