Different way to initialize vector in STL
Vector can be initialized in the different way :
vector
vector
vector
vector
All three are equal :
vector
vector
vector
How does dereferencing of Iterator in STL occurs?
An iterator has the dereference operator* defined which returns a value of a specific type – the value type of
the iterator ( just like pointer is dereferenced by the expression *pointer ) . Also like a pointer can be incremented by using the operator++, an iterator can be incremented in the same way.
Iterators most often are associated with a container. In that case, the value type of the iterator is the value type of the container and dereferencing the iterator returns an object of this value type.
What are container in STL ? What are the different type of containers
In STL .. Container is the class that holds data of other data type. There are two type of container
1. SEQUENCE CONTAINER
2. ASSOCIATIVE CONTAINER
Sequence is a kind of container that organizes a finite set of objects, all of the same type, into a strictly linear
arrangement”. STL provides three basic kinds of Sequence Containers: Vectors, Lists and Deques,
where Deque is an abbreviation for Double Ended Queue.
Associative containers provide an ability for fast retrieval of data based on keys
The elements are sorted and so fast binary search is possible for data retrieval. STL provides four
basic kinds of Associative Containers. If the key value must be unique in the container, this means, if
for each key value only one element can be stored, Set and Map can be used. If more than one element
are to be stored using the same key, Multiset and Multimap are provided
What is an Iterator class ? Difference between Input Iterator and Output Iterator ?
A class that is used to traverse through the objects maintained by a container class.
There are five categories of iterators:
Input iterators: An Input Iterator is an iterator that may be dereferenced to refer to some object, and that may be incremented to obtain the next iterator in a sequence. Input Iterators are not required to be mutable.
Output iterators:An Output Iterator is a type that provides a mechanism for storing (but not necessarily accessing) a sequence of values. Output Iterators are in some sense the converse of Input Iterators, but they have a far more restrictive interface: they do not necessarily support member access or equality, and they do not necessarily have either an associated distance type or even a value type . Intuitively, one picture of an Output Iterator is a tape: you can write a value to the current location and you can advance to the next location, but you cannot read values and you cannot back up or rewind.
Forward iterators:Forward Iterators are a refinement of Input Iterators and Output Iterators: they support the Input Iterator and Output Iterator operations and also provide additional functionality. In particular, it is possible to use “multi-pass” algorithms with Forward Iterators. A Forward Iterator may be constant, in which case it is possible to access the object it points to but not to to assign a new value through it, or mutable, in which case it is possible to do both
Bidirectional iterators:Bidirectional Iterators, like Forward Iterators, allow multi-pass algorithms. As the name suggests, they are different in that they support motion in both directions: a Bidirectional Iterator may be incremented to obtain the next element or decremented to obtain the previous element. A Forward Iterator, by contrast, is only required to support forward motion. An iterator used to traverse a singly linked list, for example, would be a Forward Iterator, while an iterator used to traverse a doubly linked list would be a Bidirectional Iterator.
Random access: Random Access Iterators allow the operations of pointer arithmetic: addition of arbitrary offsets, subscripting, subtraction of one iterator from another to find a distance, and so on.
An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class.
The simplest and safest iterators are those that permit read-only access to the contents of a container class.
