Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <iostream>
- using namespace std;
- int main() {
- int n, max = 0, min = 0;
- cin >> n;
- list<int> a;
- for (int i = 0; i < n; i++) {
- int temp = 0;
- cin >> temp;
- a.push_back(temp);
- }
- auto temp = a.begin();
- auto temp2 = a.begin();
- for (auto b = a.begin(); b != a.end(); b++) {
- if (*b > *temp) {
- max = *b;
- temp = b;
- }
- }
- for (auto b = a.begin(); b!= a.end(); b++)
- if (*temp2 < *b) {
- min = *b;
- temp2 = b;
- }
- }
- for (auto c = a.begin(); c != a.end(); с++) {
- if (*c == min && *(++c) != max) {
- a.insert(c, max);
- }
- }
- for (auto d = a.begin(); d != a.end(); d++) {
- cout << *d << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement