You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are given N integers. Sort the N integers and print the sorted order.
Store the N integers in a vector. Vectors are sequence containers representing arrays that can change in size.
Declaration:
vectorv; (creates an empty vector of integers)
Size:
int size=v.size();
Pushing an integer into a vector:
v.push_back(x);(where x is an integer.The size increases by 1 after this.)
Popping the last element from the vector:
v.pop_back(); (After this the size decreases by 1)
Sorting a vector:
sort(v.begin(),v.end()); (Will sort all the elements in the vector)
Enter link to the question(if question belongs to any online platform) -
Enter your question -
You are given N integers. Sort the N integers and print the sorted order.
Store the N integers in a vector. Vectors are sequence containers representing arrays that can change in size.
Declaration:
vectorv; (creates an empty vector of integers)
Size:
int size=v.size();
Pushing an integer into a vector:
v.push_back(x);(where x is an integer.The size increases by 1 after this.)
Popping the last element from the vector:
v.pop_back(); (After this the size decreases by 1)
Sorting a vector:
sort(v.begin(),v.end()); (Will sort all the elements in the vector)
Enter link to the question(if question belongs to any online platform) -
https://www.hackerrank.com/challenges/vector-sort/problem
Tags for the question(eg - Array, Basic, Stack, etc.) -
Sorting
The text was updated successfully, but these errors were encountered: