I want to write a class of a generic sorted list, which will always be able to insert an object to the list no matter how many objects it has already. so basically I have a homework to write a list that would act just like the STL list, which has no size limitation.
this is the class that I am thinking of:
template <class T>
class SortedList
{
T* data;
int current_size;
int max_size;
public:
//some functions
};
if I set the max_size
to 10 for example and then when ever the current_size==max_size
to expand the list size . How can I do that?
If I was writing this in c
I would simply use realloc
, however it's not possible here.
So is there a way to expand the list in c++, or a way that it could have an unlimited size?