Advertisement
jasonpogi1669

Check if Sequence is Sorted in Increasing or Decreasing Order using C++

Jun 8th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool IncreasingOrder(vector<int> a) {
  6.     if (is_sorted(a.begin(), a.end())) {
  7.         return true;
  8.     }
  9.     return false;
  10. }
  11.  
  12. bool DecreasingOrder(vector<int> a) {
  13.     if (is_sorted(a.rbegin(), a.rend())) {
  14.         return true;
  15.     }
  16.     return false;
  17. }
  18.  
  19. int main() {
  20.     int n;
  21.     cin >> n;
  22.     vector<int> a(n);
  23.     for (int i = 0; i < n; i++) {
  24.         cin >> a[i];
  25.     }
  26.     if (IncreasingOrder(a)) {
  27.         cout << "Sorted in Increasing Order!";
  28.     } else if (DecreasingOrder(a)) {
  29.         cout << "Sorted in Decreasing Order!";
  30.     } else {
  31.         cout << "Not Sorted at all!";
  32.     }
  33.     cout << '\n';
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement