https://www.hackerrank.com/challenges/vector-sort/problem
Iterators:
int size=v.size(); will give the length of vector "v" .
v.pop_back(); is used when deletion of any specific vector is required.
sort(v.begin(),v.end()); it will sort all the elements without using any loops.
v.begin() is the first element of vector and v.end() is the last element of the vector.
Member functions
- (constructor)
- Construct vector (public member function )
- (destructor)
- Vector destructor (public member function )
- operator=
- Assign content (public member function )
Iterators:
- begin
- Return iterator to beginning (public member function )
- end
- Return iterator to end (public member function )
- rbegin
- Return reverse iterator to reverse beginning (public member function )
- rend
- Return reverse iterator to reverse end (public member function )
- cbegin
- Return const_iterator to beginning (public member function )
- cend
- Return const_iterator to end (public member function )
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function )
- crend
- Return const_reverse_iterator to reverse end (public member function )
Modifiers:
Capacity:
Element access:
- assign
- Assign vector content (public member function )
- push_back
- Add element at the end (public member function )
- pop_back
- Delete last element (public member function )
- insert
- Insert elements (public member function )
- erase
- Erase elements (public member function )
- swap
- Swap content (public member function )
- clear
- Clear content (public member function )
- emplace
- Construct and insert element (public member function )
- emplace_back
- Construct and insert element at the end (public member function )
Capacity:
- size
- Return size (public member function )
- max_size
- Return maximum size (public member function )
- resize
- Change size (public member function )
- capacity
- Return size of allocated storage capacity (public member function )
- empty
- Test whether vector is empty (public member function )
- reserve
- Request a change in capacity (public member function )
- shrink_to_fit
- Shrink to fit (public member function )
Element access:
- operator[]
- Access element (public member function )
- at
- Access element (public member function )
- front
- Access first element (public member function )
- back
- Access last element (public member function )
- data
- Access data (public member function )
- get_allocator
- Get allocator (public member function )
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
vector<int>vec;
int n, nums;
cin >> n;
while (cin >> nums)
vec.push_back(nums);
sort(vec.begin(), vec.end());
for(int i=0; i<n; i++)
cout << vec[i] << " ";
return(0);
}
No comments:
Post a Comment