| | |
Not repeated elements in link list (help)
![]() |
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
•
•
•
•
I replaced it to:
while( Ptr != 0)But I still have the same problem.
I think I have to replaceif(Ptr->Info.Age == Ptr->Next)but I don't find the right way.
. cpp Syntax (Toggle Plain Text)
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(); } }
there is a link list with repeated elements remove all the repeated elements
. ![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Amazing Website Designs - How do they do this? (Site Layout and Usability)
Other Threads in the C++ Forum
- Previous Thread: Can someone please correct my pseudo code assignment? I'm new to this language.
- Next Thread: Urgent solution needed.....
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code codesamplerunwhilecommands coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph guess gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker listing loop looping loops map math matrix memory multiple news node output pointer port problem proficiency program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





