Hi,
This is a very basic question, but I can't seem to get working, I've a set of numbers that I need to display in the following, this is a class function btw.
The ouput should be something like
{ 1, 2, 3, 4, 5} (there are {} brackets and each element is seperated by a comma).
void set::display()const
{
cout << "{";
for (int i = 0; i < setlist.size(); i++)
if (setlist.at(i) == true)
cout<< i <<",";
cout << "}";
}
Just to explain, there are 100 indexes, if a particular index is true, say for example, 6 is true, the output would display 6.
There is also another code which gives me the largest number of the set.
int set::getLargest() const
{
for (int i = setlist.size()-1; i >= 0; i--)
{
if (setlist.at(i) == true)
return i;
}
}
btw setlist is actually a private which is vector<bool>setlist.
My initial idea was to use the getLargest function (which is also a class function) into the if statement, so it would be
if ((setlist.at(i)==true) && setlist.at(i) != setlist.getLargest(setlist.at(i))
cout << i << ",";
However, the compiler would not let me do that.
Can someone point me into the right direction of getting my display function to work?
Thanks.