Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.
Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators.
vector<int>v; (creates an empty vector of integers)
vector<int>v(10); (creates an integer vector of size 10)
vector<int>v(10, 0); (creates an integer vector of size 10, containing 0)
int size = v.size();
v.push_back(x); (where x is an integer.The size increases by 1 after this.)
v.pop_back(); (After this the size decreases by 1)
sort(v.begin(), v.end()); (Will sort all the elements in the vector)
// begin() - Returns an iterator pointing to the first element in the vector
// end() – Returns an iterator pointing to the theoretical element that follows the last element in the vector
Removes the element present at position.
Ex: v.erase(v.begin()+4); (erases the fifth element of the vector v)
Removes the elements in the range from start to end inclusive of the start and exclusive of the end.
Ex: v.erase(v.begin()+2,v.begin()+5); (erases all the elements from the third element to the fifth element.)
Try the following example in the editor below.
First line of the input contains an integer N denoting the number of integers.
Second line contains N space-separated integers.
Third line contains an integer X denoting the index(0-based) of the N integers which needs to be deleted.
Your task is to print the N-1 integers in sorted order (ascending). Each integer in a new line.
Constraints
1 <= N <= 105
0 <= X < N
Sample Input
5
10 5 2 3 10
2
Sample Output
3
5
10
10