Professional Documents
Culture Documents
1 - STLs I
1 - STLs I
Agenda
● Vector
● Queue
● Stack
● Deque
Vector
● Vectors are resizable dynamic arrays
● They can change their size automatically while adding or
removing elements during runtime
● They provide more flexibility than the normal static arrays
Vector
● Declare a vector:
myVector.push_back(10) ;
myVector.pop_back() ;
myVector.size() ;
Vector
● Access the third element (index 2):
myVector[2] ;
myVector[1]=6 ;
myVector.empty();
Vector
● Access the first element:
myVector.front() ;
myVector.back() ;
● Clear a vector:
myVector.clear() ;
Vector
● Iterator for the first element:
myVector.begin() ;
myVector.end() ;
sort(myVector.begin(), myVector.end());
Vector
● Iterating over all elements (normal for loop with index):
myQueue.push(5);
myQueue.pop();
Queue
● Access the first element (the next to be popped):
myQueue.front() ;
myQueue.back();
myQueue.size();
Queue
● Check if it’s empty():
myQueue.empty() ;
myStack.push(6);
myStack.pop();
Stack
● Access the top of a stack:
myStack.top() ;
myDeque.push_front(4);
myDeque.pop_front();