What Data Structure does a vector use?
Does it use an Array that increases its size when it runs out of space?
Does it use a Linked List?
Does it use a Stack?
I am talking about the vector that you get when you do
#include <vector>
What Data Structure does a vector use?
Page 1 of 16 Replies - 224 Views - Last Post: 07 January 2013 - 05:42 AM
Replies To: What Data Structure does a vector use?
#2
Re: What Data Structure does a vector use?
Posted 05 January 2013 - 06:35 PM
Did you even try cracking open the vector header file to find out yourself?
#3
Re: What Data Structure does a vector use?
Posted 05 January 2013 - 06:39 PM
#4
Re: What Data Structure does a vector use?
Posted 05 January 2013 - 06:47 PM
Look at your INCLUDE environment variable. It should list which directories the VS compiler searches to find header files.
#5
Re: What Data Structure does a vector use?
Posted 05 January 2013 - 11:23 PM
qkrtjdwls91, on 06 January 2013 - 01:39 AM, said:
U can do that? O.O where does visual studio 2010 keep its header files? in windows 7
In VS you can just right click the #include <vector> line and go to "Open Document", although you should be able to find vector in "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src".
What concrete data structure does a vector use? This might shed some light on the subject. Basically, it's a contiguous array of elements as far as I know.
This post has been edited by Aphex19: 05 January 2013 - 11:36 PM
#6
Re: What Data Structure does a vector use?
Posted 06 January 2013 - 08:56 PM
It uses a dynamically allocated array, with two unique members that describe it (size and capacity). The size refers to the number of elements occupying the vector, the other describes the physically size of the dynamic array.
#7
Re: What Data Structure does a vector use?
Posted 07 January 2013 - 05:42 AM
Technically, it uses whatever the hell it likes. It need only support it's public methods. The implementation is irrelevant. Isn't Object Oriented Programming grand?
In practice, there's usually an array involved. This is because random access is more expensive in other structures. However, you could have an array of arrays, so reallocation isn't so expensive... It you were on an architecture that used something like static sized memory pages, you'd might take advantage of that.
Those are implementation details. The user of the class should never have to be concerned with such things.
In practice, there's usually an array involved. This is because random access is more expensive in other structures. However, you could have an array of arrays, so reallocation isn't so expensive... It you were on an architecture that used something like static sized memory pages, you'd might take advantage of that.
Those are implementation details. The user of the class should never have to be concerned with such things.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|