Advertisement
vaibhav1906

Sorting

Nov 18th, 2021
1,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool compare(int a, int b){
  4.    
  5.     if(a>b){
  6.         return true;
  7.     }
  8.    
  9.     return false;
  10.    
  11. }
  12. int main(){
  13.    
  14.     vector<int>v;
  15.     v.push_back(64); v.push_back(71) ;v.push_back(32) ; v.push_back(81) ; v.push_back(93); v.push_back(78);
  16.     sort(v.begin(), v.end());
  17.    
  18.     cout<<"in asending order : "<<endl;
  19.    
  20.     for(int i = 0; i<v.size(); i++){
  21.         cout<<v[i]<<" ";
  22.     }
  23.     cout<<endl;
  24.     sort(v.begin(), v.end(), compare);
  25.     cout<<"in desending order : "<<endl;
  26.    
  27.     for(int i = 0; i<v.size(); i++){
  28.         cout<<v[i]<<" ";
  29.     }
  30.     cout<<endl;
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement