HI!
I have been told to write a class like "vector" class.
I wanted to start writing a class that creates linked lists, but before that I wanted to make sure if VECTOR uses linked lists or not?
Is there any other method like that?
THNX
A vector does not use linked lists, which are just pointers to the next/previous element. A vector is sequential in memory so it cannot be HUGE and can access memory directly.
Btw I don't know exactly how all this is implemented. I'm pretty sure a vector is just an array that makes a new array with twice the amount of space when the limit is reached.
For example if you have 2 elements in a vector and you push another one in then it makes a whole new array with 4 spaces and copies every element over with the new element.
Thanks @AlitCandle
So how should I write a vector class?
Should I use simple arrays and everytime user wants to add or delete some data, I should make a copy of that with new datas?
I don't think that's a good way (considering time and operations).
Sorry I'm asking here, but what should I do?
I don't have much time for research, may you guide me?
my exam day Is approaching.
THNX
I'm pretty sure a vector is just an array that makes a new array with twice the amount of space when the limit is reached.
I think that's roughly right, though it seems to be compiler dependent. I tried testing the capacity of a vector using two different compilers, one seemed to double the size every time it was filled up, the other did a more modest 50% size increase.