C++ STL – Standard Template Library

STL – Standard Template Library

Collections of useful classes for common data structures
Ability to store objects of any type (template)
Study of containers
Containers form the basis for treatment of data structures
Container – class that stores a collection of data
STL consists of 10 container classes:
Sequence containers
Adapter containers
Associative containers

STL Containers

Sequence Container
Stores data by position in linear order:
First element, second element , etc:
Associate Container
Stores elements by key, such as name, social security number or part number
Access an element by its key which may bear no relationship to the location of the element in the container
Adapter Container
Contains another container as its underlying storage structure
Sequence Container
Vector
Deque
List
Adapter Containers
Stack
Queue
Priority queue
Associative Container
Set, multiset
Map, multimap

Vector Container

Generalized array that stores a collection of elements of the same data type
Vector – similar to an array
Vectors allow access to its elements by using an index in the range from 0 to n-1 where n is the size of the vector
Vector vs array
Vector has operations that allow the collection to grow and contract dynamically at the rear of the sequence
Allows direct access to the elements via an index operator
Indices for the vector elements are in the range from 0 to size() -1
Example:
#include
vector v(20);
v[5]=15;
See
http://cs.smu.ca/~porter/csc/ref/stl/cont_vector.html
For list of vector operations.

LIST CONTAINER

Stores elements by position
Each item in the list has both a value and a memory address (pointer) that identifies the next item in the sequence
To access a specific data value in the list, one must start at the first position (front) and follow the pointers from element to element until data item is located.
List is not a direct access structure
Advantage: ability to add and remove items efficiently at any position in the sequence

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *