Translate

Total Pageviews

Tuesday, June 30, 2020

PROBLEM: Vector-Sort

https://www.hackerrank.com/challenges/vector-sort/problem

  • 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.
FOR MORE DETAILS ABOUT  VECTORS

Member functions


Iterators:
Modifiers:

Capacity:

Element access:
Allocator:

#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