Advertisement
Andites

timp 2.5

Nov 12th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <list>
  6. using namespace std;
  7. const int N = 10;
  8. void per(list <int> &l) {
  9. list <int> ch;
  10. list <int> nch;
  11. for (auto n : l) { //вывод значений списка
  12. cout << n << " ";
  13. }
  14. cout << endl;
  15. for (auto it = l.begin(); it != l.end(); it++) {
  16. if (distance(l.begin(), it) % 2 == 0) {
  17. nch.push_back(*it);
  18. }
  19. }
  20. for (auto it = l.begin(); it != l.end(); it++) {
  21. if (distance(l.begin(), it) % 2 != 0) {
  22. ch.push_back(*it);
  23. }
  24. }
  25. cout << "nech\n";
  26. for (auto n : nch) {
  27. cout << n << " ";
  28. }
  29. cout << endl << "ch\n";
  30. for (auto n : ch) {
  31. cout << n << " ";
  32. }
  33.  
  34. l.clear();
  35. for (auto it = nch.begin(); it != nch.end(); it++) {
  36. l.push_back(*it);
  37. }
  38. for (auto it = ch.begin(); it != ch.end(); it++) {
  39. l.push_back(*it);
  40. }
  41.  
  42. }
  43. int main()
  44. {
  45. setlocale(LC_ALL, "Russian");
  46. list <int> l;
  47. for (int i = 0; i < N; i++) { //ввод значений списка
  48. l.push_back(rand() % 10);
  49. }
  50.  
  51. per(l);
  52. cout << endl << "OUTPUT: \n";
  53. for (auto n : l) { //вывод значений списка
  54. cout << n << " ";
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement