SHARE
TWEET

Untitled

a guest Jan 24th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4. #include <list>
  5. #include <forward_list>
  6. using namespace std;
  7.  
  8. void EraseAtPos(int Pos, list<int>& L)
  9. {
  10.     list<int>::iterator It = L.begin();
  11.     int i = 0;
  12.     while (i < Pos)
  13.     {
  14.         It++;
  15.         i++;
  16.     }
  17.     L.erase(It);
  18.  
  19. }
  20. void DoOperations(list<list<int>>& L){
  21.     int pos = 0;
  22.     bool isEven = false;
  23.     int i = 0;
  24.     list<list<int>>::iterator It;
  25.     for (It = L.begin(); It != L.end(); ++It)
  26.     {
  27.         if (L.size() % 2 == 0)
  28.         {
  29.             if (isEven)
  30.             {
  31.                 i = 1;
  32.                 isEven = false;
  33.             }
  34.             else
  35.             {
  36.                 i = 0;
  37.                 isEven = true;
  38.             }
  39.         }
  40.         else
  41.         {
  42.             i = 0;
  43.         }
  44.         pos = i;
  45.         while (i < It->size())
  46.         {
  47.             EraseAtPos(pos, *It);
  48.             pos++;
  49.             i++;
  50.         }
  51.     }
  52. }
  53. int main()
  54. {
  55.  
  56.     list<list<int>> GList;
  57.     //GList.resize(10);
  58.  
  59.     list<int> l1;
  60.     //l1.resize(10);
  61.     l1.push_back(1);
  62.     l1.push_back(2);
  63.     l1.push_back(3);
  64.     l1.push_back(4);
  65.     //l1.push_back(20);
  66.  
  67.     list<int> l2;
  68.     //l2.resize(10);
  69.     l2.push_back(5);
  70.     l2.push_back(6);
  71.     l2.push_back(7);
  72.     l2.push_back(8);
  73.     //l2.push_back(21);
  74.    
  75.     list<int> l3;
  76.     //l3.resize(10);
  77.     l3.push_back(9);
  78.     l3.push_back(10);
  79.     l3.push_back(11);
  80.     l3.push_back(12);
  81.     //l3.push_back(22);
  82.    
  83.     list<int> l4;
  84.     //l4.resize(10);
  85.     l4.push_back(13);
  86.     l4.push_back(14);
  87.     l4.push_back(15);
  88.     l4.push_back(16);
  89.     //l4.push_back(22);
  90.  
  91.     list<int> l5;
  92.     //l5.push_back(30);
  93.     //l5.push_back(40);
  94.     //l5.push_back(50);
  95.     //l5.push_back(60);
  96.     //l5.push_back(70);
  97.  
  98.  
  99.  
  100.     GList.push_back(l1);
  101.     GList.push_back(l2);
  102.     GList.push_back(l3);
  103.     GList.push_back(l4);
  104.     //GList.push_back(l5);
  105.  
  106.     list<list<int>>::iterator Iter;
  107.     for (Iter = GList.begin(); Iter != GList.end(); ++Iter)
  108.     {
  109.         list<int> sublist = *(Iter);
  110.         list<int>::iterator SubIt;
  111.         for (SubIt = sublist.begin(); SubIt != sublist.end(); ++SubIt)
  112.         {
  113.             cout << *(SubIt) << " ";
  114.         }
  115.         cout << endl;
  116.     }
  117.  
  118.  
  119.     DoOperations(GList);
  120.     for (Iter = GList.begin(); Iter != GList.end(); ++Iter)
  121.     {
  122.         list<int> sublist = *(Iter);
  123.         list<int>::iterator SubIt;
  124.         for (SubIt = sublist.begin(); SubIt != sublist.end(); ++SubIt)
  125.         {
  126.             cout << *(SubIt) << " ";
  127.         }
  128.         cout << endl;
  129.     }
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top