Sort using vector in c++

The below program prints the input numbers in a sorted order.The program is implemented using c++.

Output :


Code :


#include<bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> s;
    int n;
    cout<<"Enter number of elements : ";
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        s.push_back(t);
    }
    sort(s.begin(),s.end());
    cout<<"Sorted Order :"<<endl;
    for(int i=0;i<n;i++)
        cout<<s[i]<<" ";
    return 0;
}

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Bit Stuffing Code Implementation in Java

Hackerrank Modified Kaprekar Numbers Solution