|
I see what you're saying, that's what I thought too. I asked my professor on this and for the scope of this assignment he said it would be acceptable to increment the array by 1 each time, however there are more ways to do this. growing it by a factor of 2 I think will be the best option because when dealing with small or large cases, the array will not need to be resized and moved N times, rather something approaching logN, evening out the curve as 100's or 1000's of elements need to be added.
I also agree with your suggestion that a vector or list would have worked great, but the requirement was that I don't use any STL, just to get me back in the groove of things with pointers. In light of this, sad to say, this is my first real self-introduction into dynamic memory allocation. I've used malloc/realloc/free and new/delete, but never in respects to resizing an array as required, and am not familiar with the tried and tested ways of resizing an array. With my implementation, I tried to reduce the amount of times the array will have to be resized.
Thanks for the tips redhead
|