Information: the function is supposed to print out multiple "sets" of users. Think of it as separate groups of friends, all interconnected within each group, but nobody in any group is connected to anybody outside their group.
My problem: the function only prints the first set (all users connected to user 0, since that's where I manually start the loop). There are supposed to be four sets.
void list_sets()
{
if (! Users.size()) cout << "\tNo users in database." << endl;
else {
deque<int> queue;
int numsets = 0;
int current;
unsignedint numchecked = 1;
while (numchecked < Users.size()) { // Users is a vector of 44 elements
numsets++;
queue.clear();
int j = 0;
while (! queue.size()) {
if (! Users[j].checked) queue.push_back(j);
else j++;
}
current = queue[0];
Users[current].checked = true;
cout << "\nSet " << numsets << " => " << Users[current].username;
while (queue.size()) {
for (unsignedint i = 0; i < Users[current].friends.size(); i++) {
if (! Users[Users[current].friends[i]].checked) {
cout << ", ";
cout << Users[Users[current].friends[i]].username;
queue.push_back(Users[current].friends[i]);
Users[Users[current].friends[i]].checked = true;
numchecked++;
}
if (numchecked == Users.size()) break;
}
queue.pop_front();
if (queue.size()) current = queue[0]; Users[current].checked = true;
if (numchecked == Users.size()) break;
}
if (numchecked == Users.size()) cout << endl; break;
}
}
}
I've done tons of error-checking by inserting cout tests and I can't find out why the while (numchecked < Users.size()) loop won't iterate even a second time, let alone a fourth time. Any help will be appreciated.
EDIT: Forgot to specify that Users is a vector of User objects, which contain a bool member called checked, which just determines whether or not that User has been put in a "set" yet.