I need to move through list elements and add them to the set. However, while moving through list I need to skip elements that are already added to set. First element of list is added to set before moving through list.
For example:
{"Damir", "Ana", "Muhamed", "Marko", "Ivan","Mirsad", "Nikolina", "Alen", "Jasmina", "Merima"}
Enter shift: 5
Mirsad
Enter shift: 6
Muhammed
Enter shift: 7
Ana
EXPLANATION:
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <set>
void Moving_Trough_List(std::vector<std::string>names) {
int n = names.size(), shift = 0;
std::list<std::string>lista;
for (int i = 0; i < n; i++) {
lista.push_back(names[i]);
}
std::set<std::string>team;
auto it = lista.begin();
auto temp = it;
int index_list = 0;
while (shift != -1) {
std::cout << "Enter shift: ";
std::cin >> shift;
std::cin.ignore(100, '\n');
for (int i = 0; i < shift; i++) {
index_list++;
}
if (index_list > n - 1)
index_list = index_list - n + 1;
while (it != temp)
it--;
for (int i = 0; i < index_list; i++)
it++;
std::cout << *it << "\n";
team.insert(*it);
}
std::cout << std::endl;
for (auto i : team)
std::cout << i << " ";
}
int main ()
{
Moving_Trough_List({"Damir", "Ana", "Muhamed", "Marko", "Ivan",
"Mirsad", "Nikolina", "Alen", "Jasmina", "Merima"
});
return 0;
}
MY OUTPUT:
Enter shift: 5
Mirsad
Enter shift: 6
Muhammed
Enter shift: 7
Merima
So it worked correctly for shift 5 and 6, but after that it didn't skip elements already added to set. Could you help me to modify this to skip already added elements to set?