Hi.
I want my Insertion method in my link list class not to insert repeated elements. I have tried several ways but I have seriously ugly bugs in my code:
template <typename ListElement>
void List <ListElement>::Insert()
{
NodePtr Ptr;
Ptr = new Node;
bool repeated = true;
if (Ptr == NULL)
{
cout << "Error: Insuficient Storage " << endl;
exit(1);
}
cout << " Enter The Social Security Number of New Student: ";
cin >> Ptr->Info.SSN;
cout << "Enter The Age of This Student: ";
cin >> Ptr->Info.Age;
while( Ptr->Next != NULL)
{
if(Ptr->Info.Age == Ptr->Next->Info.Age)
repeated = false;
break; // This break is for not to add the element
Ptr = Ptr->Next;
}
Ptr->Next = Head;
Head = Ptr;
if(repeated = false)
cout << "repetition just ocurred" << endl; // This is just 4 me to verified if the function works
}
What do you think it is? Thanks