mercredi 3 février 2016

Set function in c++ not working

Im writing a Set class in c++(i know there is already a library this is an assignment) and similar to the one in C++ im writing a function to check if the entry being inputted is already in the set

void Set::insert(const Set::value_type& entry) 
{

    for (int i=0; i<used;i++)
        {
            if(data[i]!=entry && used<CAPACITY)
            {
                data[used] = entry;
                used++;
            }
            else 
            {
                throw "Out of capacity in Set and Intger already in Set";
            }
        }

}

What the function does is look if the number is in the set. If the number is not in the set and if used < capacity (meaning their is still room) then the number is inserted. When i use the insert function nothing happens. Could someone help me out. Maybe im approaching this the wrong way.

Aucun commentaire:

Enregistrer un commentaire