Warning: These libraries are deprecated. You may try to use them, but chances are they will not work on most new compilers.

Apvector is a wonderful little class that dynamically (meaning it can be changed) stores an array (or list) of any data type of information. Was that sentence greek? Think of a green bean. It stores all of the little beans under that one big pod. But this bean can get bigger and smaller on command...and it can store more than just beans! Still confused? Don't worry, you'll (hopefully) get it by the end of this lesson. Now, on to the class. You declare it somewhat like you declared apstring. But there are a few differences. With apvector, you can assign its length, or the number of items in the list (the number of beans in the pod), and you can also assign a value to fill each item in the list. All of that on one line! You also have to assign it a data type. You do that by placing a <data_type> right after the word apvector in your declaration. It is really simple. Here's how ya do it:

apvector<int> myvector;

Creates an array, or list, with the capacity to store integer values.

apvector<apstring> myvector(5);

Creates an array with 5 items in the list, each capable of storing an apstring.

apvector<double> myvector(5,2);

Creates an array with 5 items in the list, each capable of storing a double, and each item is initialized to 2.

Apvector also uses indexing to access the values. You do it the same way as in apstring. just use the variable name, here it is myvector, and use the []'s after it with the index of the item you want inside the []'s. I might as well give a clearer description of exactly what apvector does right now, so here we go! I am using an apvector of type int called myvector, which I declared, that has 5 items in its list, and the following number in each item.

apvector<int> myvector(5);

myvector[0] = 3;
myvector[1] = 5;
myvector[2] = 8;
myvector[3] = 15;
myvector[4] = 22;

myvector[k]:           k = 0   k = 1   k = 2   k = 3   k = 4
value in myvector[k]:    3       5       8      15      22

Notice that an apvector with 5 items starts from 0 and goes to 4. So when you enter myvector[1], it will represent the value 5 - the second value in the list, and myvector[3] represents 15 - the fourth value in the list! Be careful with this, though. If you accidentally enter myvector[5], you will get an illegal vector index error and the program will stop.

Alright, now time for the meat of this class. Apvector doesn't have many real awesome functions. Just your basic, run of the mill modifier functions. There is the length() function, which finds the length, or number of items, in the particular apvector. This does function does not use indexing, so my_vector[my_vector.length()] will give you an illegal vector index. You've gotta put a - 1 in there to make it grab the last item in the list. Anywho, there is also a resize function, which resizes the vector. You use them like so:

int myVectorLength;
apvector<int> myVector(5,0);

This declares an int, myVectorLength, and an apvector, myVector, where myVector is a list of 5 integer values, each of which is initialized to 0.

myVectorLength = myVector.length();

This assigns myVectorLength the length of myVector. Remember! The length() function doesn't use indexing; it starts counting from 1. Like any function that returns a value, you don't have to assign it to anything when you call it. You can use it in a cout statement to quickly output the length of the vector without assigning it to a variable.

Now, the resize function takes in the new size that you want the vector to have. Note that it takes the "real" length as well, rather than the index, so you'll have to add one to the length in order to make it one 'cell' bigger. Like so:

myVector.resize(myVector.length()+1);  

This here code just raises the capacity of the list by one. It takes the length of apvector (myVector.resize(myVector.length() +1)), which is 5, and adds 1 to it, resulting in the vector being 6 units long. Notice how the length() function was used as any normal number.

myVector.resize(myVectorLength);

This resizes the list to the size of myVectorLength, which is 5. Note that this will make the list smaller, and it will cut off the last values in the list if you do it, which may not be intentional, so be careful when using this funtion. In this example it would cut off the 6th value, which is empty. Just so you know!