Advertisement
newvol

List Experiments

May 11th, 2023
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <list>
  2. #include <iostream>
  3. using namespace std;
  4. int main() {
  5.   int n, max = 0, min = 0;
  6.   cin >> n;
  7.   list<int> a;
  8.  
  9.   for (int i = 0; i < n; i++) {
  10.     int temp = 0;
  11.     cin >> temp;
  12.     a.push_back(temp);
  13.   }
  14.   auto temp = a.begin();
  15.   auto temp2 = a.begin();
  16.   for (auto b = a.begin(); b != a.end(); b++) {
  17.     if (*b > *temp) {
  18.       max = *b;
  19.       temp = b;
  20.     }
  21.   }
  22.  
  23.   for (auto b = a.begin(); b!= a.end(); b++)
  24.     if (*temp2 < *b) {
  25.       min = *b;
  26.       temp2 = b;
  27.     }
  28.   }
  29.  
  30.   for (auto c = a.begin(); c != a.end(); с++) {
  31.     if (*c == min && *(++c) != max) {
  32.       a.insert(c, max);
  33.     }
  34.   }
  35.  
  36.   for (auto d = a.begin(); d != a.end(); d++) {
  37.     cout << *d << " ";
  38.   }
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement