| | |
Not repeated elements in link list (help)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





