Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
const int maxsize=100;
int tempi;
bool barray=new bool[maxsize];
for (tempi=0;tempi<maxsize;tempi++) barray[tempi]=false;//not as effiecient as memset
while(notdone)
{
tempi=getnextInt();
if (tempi>=maxsize) throw "Out of bounds"; //alternativly
//tempi%=maxsize;
if (!barray[tempi])
{
//do stuff
barray[tempi]=true;
}
//optionally
//else
//{
//do other stuff
//}
}
an alternative bounds safe approach would be to use a container class (say a list or a btree) to hold all of the ones that you have used. Instead of checking that element in the array you would check to see if that element was in the set. The drawback to this is a minor speed hit. It is probabally worth it to be able to handle data without bounds.
that approach would look something like
int tempi;
list intlist;
while(condition)
{
tempi=getnextInt();
if (intlist.find(tempi)==-1) //notfound
{
//do stuff
intlist.add(tempi);
}
else
{
//do other stuff
}
}
} WR