<zf*****@mail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
I'm sorry guys, I promise this is the last question. Here is my code
in main:
<code>
infile >Item;
if(list1.IsThere(Item))
cout << "Item duplicate!" << endl;
else
{ list1.Insert(Item);
infile >Item;
while(!(list1.IsThere(Item)))
{ while(infile)
{
if(!(list1.IsThere(Item)))
{
list1.Insert(Item);
infile >Item;
}
infile >Item
}
This block of code is confusing. I'm not quite sure what you are trying to
accomplish, as you are reding input in 3 different places, inserting in 2,
checking for duplicates in 3, and only displaying "Item Duplicate!" once.
Are you tryign to read the items until the end and simply not entering the
item if it's a duplicate, but then reading the rest? Or are you trying to
stop on any duplicate?
Wouldn't something like this be better?
while ( infile >item )
if ( list1.IsThere(Item) )
{
cout << "Item Duplicate!" << endl;
// break
// Uncomment break if you want to halt on any duplicate
}
else
list1.Insert(Item);
>
}
</code>
and the search function
<code>
bool List::IsThere(ItemType Item) const
// Post: If item is in the list IsThere is
// True: False otherwise
{
NodePtr loopPtr;
loopPtr = listPtr;
while(loopPtr)
{
if (loopPtr->item == Item)
{
return true;
}
loopPtr = loopPtr-next;
}
return false;
}
</code>
Will this work?