Say I have an array like this:

double *a;

and I use new/delete[] to do memory allocation on it.

How would I be able to delete certain elements from it?

Like this:

void RemoveElement(double *a, const double &element)
{

}

Recommended Answers

All 5 Replies

Why not use a std::list instead?

because i'm trying to make my own version of the std::vector class..

If you're storing things in an array (contiguous memory), I believe the only way to delete an element from the middle is to shift all of the elements after it to the left. If operations like this are frequently required, the linked list data structure is preferred to the array.

Dave

That is a good idea. But how would I implement the [] operators if it's not an array, but a linked list?

i guess i could have it so each "link" has an id..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.