fbpx

C++ STL containers including differences of list vs vector

(Last Updated On: May 18, 2010)

C++ STL containers including differences of list vs vector
Vector –
1> Insertion – O(n) /* Resizing the array */
2> Search – O(n) /* Sequential */ , O(logn ) /* Binary */
3> Random Access – Yes .
4> Deletion – O(n) /* Shifting & Resizing */
5> Sequential Memory used .

List –
1> Insertion – O(1)
2> Search – O(n)
3> Deletion – O(n)
4> Random Access – No
5> Linked allocation , hence more memory efficient
The above are known as containers found in the Standard Temple Library (STL) They also contain predefined behaviour and are well known interfaces.
Below is a C++ source example of a list:
// Standard Template Library example

#include
#include using namespace std;

// Simple example uses type int

int main()
{
list L;
L.push_back(0); // Insert a new element at the end
L.push_front(0); // Insert a new element at the beginning
L.insert(++L.begin(),2); // Insert “2” before position of first argument
// (Place before second argument)
L.push_back(5);
L.push_back(6);

list::iterator i;

cout << "before remove" <
#include

using namespace std;

main()
{
vector< vector > vI2Matrix; // Declare two dimensional array
vector A, B;
vector< vector >::iterator iter_ii;
vector::iterator iter_jj;

A.push_back(10);
A.push_back(20);
A.push_back(30);
B.push_back(100);
B.push_back(200);
B.push_back(300);

vI2Matrix.push_back(A);
vI2Matrix.push_back(B);

cout << endl << "Using Iterator:" << endl; for(iter_ii=vI2Matrix.begin(); iter_ii!=vI2Matrix.end(); iter_ii++) { for(iter_jj=(*iter_ii).begin(); iter_jj!=(*iter_ii).end(); iter_jj++) { cout << *iter_jj << endl; } } } Need finer detail of this with examples of map and multimap!!

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
Don't miss out!
Get my TRADE LIKE A BOSS 2 PDF Books

You will received instantly the download links.

Invalid email address
Give it a try. You can unsubscribe at any time.

NOTE!

Check NEW site on stock forex and ETF analysis and automation

Scroll to Top