Skip to content

Commit

Permalink
Merge pull request srbcheema1#1 from harjot3200/harjot3200-patch-1
Browse files Browse the repository at this point in the history
sorting a vector
  • Loading branch information
DarthCoder3200 authored Oct 1, 2017
2 parents 0bc1393 + 0c8bdfd commit 9de89c9
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sorting_a_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

bool compare(int a,int b){
return a>b;
}

int main(){

vector<int> v;

for(int i=1;i<5;i++){
v.push_back(i);
}
int p;
cin>>p;

int d;
cin>>d;

v.insert(v.begin() + p,d);

for(int i=0;i<v.size();i++){
cout<<v[i]<<" ";
}
cout<<endl;
///Sort a vector
sort(v.begin(),v.end(),compare);

for(int i=0;i<v.size();i++){
cout<<v[i]<<" ";
}



return 0;
}

0 comments on commit 9de89c9

Please sign in to comment.