What does "VECTOR" exactly do?

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 is included with C++ in the standard library.

http://www.cplusplus.com/reference/vector/vector/

A linked list:

http://www.cplusplus.com/reference/list/list/

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.
Last edited on
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 always thought vectors were pretty much container classes.
This page explains it better than i would be able to.

http://www.learncpp.com/cpp-tutorial/104-container-classes/

Hope it helps with writing the class :)
AlitCandle wrote:
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.
If you know what templates are use those.
http://m.youtube.com/watch?v=GoMNA4dYXvE&feature=plpp

Sorry for mobile. The video is C++ Basic Skills: Lesson 28 "Our Expandable Array Class" by the user outofmylabratory.
Last edited on
Topic archived. No new replies allowed.