Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <list>
- using namespace std;
- const int N = 10;
- void per(list <int> &l) {
- list <int> ch;
- list <int> nch;
- for (auto n : l) { //вывод значений списка
- cout << n << " ";
- }
- cout << endl;
- for (auto it = l.begin(); it != l.end(); it++) {
- if (distance(l.begin(), it) % 2 == 0) {
- nch.push_back(*it);
- }
- }
- for (auto it = l.begin(); it != l.end(); it++) {
- if (distance(l.begin(), it) % 2 != 0) {
- ch.push_back(*it);
- }
- }
- cout << "nech\n";
- for (auto n : nch) {
- cout << n << " ";
- }
- cout << endl << "ch\n";
- for (auto n : ch) {
- cout << n << " ";
- }
- l.clear();
- for (auto it = nch.begin(); it != nch.end(); it++) {
- l.push_back(*it);
- }
- for (auto it = ch.begin(); it != ch.end(); it++) {
- l.push_back(*it);
- }
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- list <int> l;
- for (int i = 0; i < N; i++) { //ввод значений списка
- l.push_back(rand() % 10);
- }
- per(l);
- cout << endl << "OUTPUT: \n";
- for (auto n : l) { //вывод значений списка
- cout << n << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement