211122222
11220212
22222111
111123
222222
1
11111
and after that
211122222
11222212
22222111
111123
2222 2
1
11111
I want something like that
211122222
11222212
22222111
111123
22222
1
11111
if the list is unordered, swap the deleted element with the last element and decrease size variable by 1, optionally re-alloc but this should be avoided until you have a bunch of wasted space as it is very slow.
if it is ordered, memmove the data one location and decrease size, optionally realloc. Its not that much more expensive for small lists to use one of the sorts that does little to no work for nearly sorted lists (eg shell / insertion) but memmove is going to be faster for bigger blocks.
better, use a <vector> and erase() if this is C++. You are trying to do C stuff here.
memmove is in bytes. sizeof(type)*numberoftype is what is usually stuck in there.
so if you had
int i[] = {0,1,2,3,4,5};
memmove(i, &(i[1], 5*sizeof(int)); //I think this is what you want
that would 'remove' the zero. The 6th location remains 5, but you would have said
somesize--; so you would never access the 'empty' location because its out of your defined range now.
I havent done this stuff in a while, so you would be wise to double check the memmove function documentation. I am pretty sure they are all of the format (destination, source, #bytes). memmove is for unsafe operations (destination and source overlap). Memcpy is used if they do not overlap (its more efficient). By definition of what you asked to do, it overlaps.