Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- #include <list>
- #include <forward_list>
- using namespace std;
- void EraseAtPos(int Pos, list<int>& L)
- {
- list<int>::iterator It = L.begin();
- int i = 0;
- while (i < Pos)
- {
- It++;
- i++;
- }
- L.erase(It);
- }
- void DoOperations(list<list<int>>& L){
- int pos = 0;
- bool isEven = false;
- int i = 0;
- list<list<int>>::iterator It;
- for (It = L.begin(); It != L.end(); ++It)
- {
- if (L.size() % 2 == 0)
- {
- if (isEven)
- {
- i = 1;
- isEven = false;
- }
- else
- {
- i = 0;
- isEven = true;
- }
- }
- else
- {
- i = 0;
- }
- pos = i;
- while (i < It->size())
- {
- EraseAtPos(pos, *It);
- pos++;
- i++;
- }
- }
- }
- int main()
- {
- list<list<int>> GList;
- //GList.resize(10);
- list<int> l1;
- //l1.resize(10);
- l1.push_back(1);
- l1.push_back(2);
- l1.push_back(3);
- l1.push_back(4);
- //l1.push_back(20);
- list<int> l2;
- //l2.resize(10);
- l2.push_back(5);
- l2.push_back(6);
- l2.push_back(7);
- l2.push_back(8);
- //l2.push_back(21);
- list<int> l3;
- //l3.resize(10);
- l3.push_back(9);
- l3.push_back(10);
- l3.push_back(11);
- l3.push_back(12);
- //l3.push_back(22);
- list<int> l4;
- //l4.resize(10);
- l4.push_back(13);
- l4.push_back(14);
- l4.push_back(15);
- l4.push_back(16);
- //l4.push_back(22);
- list<int> l5;
- //l5.push_back(30);
- //l5.push_back(40);
- //l5.push_back(50);
- //l5.push_back(60);
- //l5.push_back(70);
- GList.push_back(l1);
- GList.push_back(l2);
- GList.push_back(l3);
- GList.push_back(l4);
- //GList.push_back(l5);
- list<list<int>>::iterator Iter;
- for (Iter = GList.begin(); Iter != GList.end(); ++Iter)
- {
- list<int> sublist = *(Iter);
- list<int>::iterator SubIt;
- for (SubIt = sublist.begin(); SubIt != sublist.end(); ++SubIt)
- {
- cout << *(SubIt) << " ";
- }
- cout << endl;
- }
- DoOperations(GList);
- for (Iter = GList.begin(); Iter != GList.end(); ++Iter)
- {
- list<int> sublist = *(Iter);
- list<int>::iterator SubIt;
- for (SubIt = sublist.begin(); SubIt != sublist.end(); ++SubIt)
- {
- cout << *(SubIt) << " ";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement