I replaced it to:
while( Ptr != 0)
But I still have the same problem.
I think I have to replace if(Ptr->Info.Age == Ptr->Next)
but I don't find the right way.
Here is a sample code, thanks for your efforts :).
template<class T>
class Node {
T _element;
Node* _next;
public:
Node(const T& element, Node* next = 0) : _element(element), _next(next) {}
T Element() const { return _element; }
Node*& Next() { return _next; }
};
template<class T>
class LinkList {
Node<T>* _head;
public:
LinkList() : _head(0) {}
bool Insert(const T& element);
void PrintList() const;
};
template<class T>
bool LinkList<T>::Insert(const T& element)
{
if (!_head) {
_head = new Node<T>(element);
return true;
}
if (element == _head->Element ()) {
return false;
}
// Temporary pointer to head.
Node<T>* _headIter = _head;
bool bRepeated = false;
while (_headIter->Next()) {
if (element == _headIter->Element()) {
bRepeated = true;
}
_headIter = _headIter->Next();
}
if (bRepeated) {
cout<<" Repeated: element is : "<< element <<endl;
}
else {
_headIter->Next() = new Node<T>(element);
}
return true;
}
template<class T>
void LinkList<T>::PrintList() const
{
Node<T>* _headIter = _head;
while (_headIter) {
cout<<"The element is : " << _headIter->Element()<<endl;
_headIter = _headIter->Next();
}
}
try to acheive this task its interesting one
there is a link list with repeated elements remove all the repeated elements :).