Imran_Mohammed

Vector Task

Jan 24th, 2021 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1.        // In The Name Of Allah
  2.  
  3. #include<bits/stdc++.h>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //Vector Declare :
  10.     vector <int> a;
  11.     a.push_back(2);
  12.     a.push_back(3);
  13.     cout << a[0] << " " << a[1] <<endl;//2 3*/
  14.  
  15.     //Vector Input :
  16.     int n;
  17.     cin >> n;
  18.     vector<int>v;
  19.  
  20.     for(int i=0; i<n; i++){
  21.         int a;
  22.         cin >> a;
  23.         v.push_back(a);
  24.     }
  25.  
  26.     cout << v.size() << endl;//size Of Vector
  27.  
  28.     for(int i=0; i<n; i++){
  29.         cout << v[i] << " ";
  30.     }
  31.     cout << endl;
  32.  
  33.     //v/.empty()  == empty or not check
  34.  
  35.     //v.resize() == Increasing Vector Size
  36.  
  37.     //v.begin() == 0 Number Index
  38.  
  39.     //v.end() , v.back() == last Number Index
  40.  
  41.     //For Each Loop :
  42.     for(auto u:v){
  43.         cout << u << " ";
  44.     }
  45.     cout << endl;
  46.  
  47.     // Complexity Of Sort : 0( n log2(n) )
  48.     sort(v.begin(),v.end()); //Small To Greater
  49.     sort(v.rbegin(),v.rend()); //Greater To small
  50.  
  51.     //Unique Vector :
  52.     sort(v.begin() , v.end());
  53.     int sz = unique( v.begin(),v.end()) - v.begin();
  54.  
  55.     // Index Of Maximum Or Minimum Element :
  56.     int p = max_element(v.begin(),v.end() ) - v.begin();
  57.     int q = min_element(v.begin(),v.end() ) - v.begin();
  58.  
  59.     cout << p << " " << q << endl;
  60.  
  61.  
  62.     //Frequency Count of givenb number :
  63.       int c = count(v.begin() , v.end() , x);
  64.        cout << c << endl;
  65.  
  66.     return 0;
  67. }
  68.  
Add Comment
Please, Sign In to add comment