I have a linked list in C++ and I am trying to remove all duplicate nodes from the list. The code below is what our prof. wrote on the board in pusdo code in class, yet it doesn't seem to be working correctly for me. I also need to preface that the list is not sorted. Prior to entering this part of the code we need to link two preexising lists together. The directions do not say to sort the two list once they are put together.
Any advice would be helpful.
Thanks
Expand|Select|Wrap|Line Numbers
- r = first;
- while ( r != nil )
- {
- target = (*r).info;
- q = r;
- p = (*q).next;
- while ( ((*p).next != nil) )
- {
- if ( target == (*p).info )
- {
- (*q).next = (*p).next;
- }
- else
- {
- q = p;
- p = (*p).next;
- }//end if
- }//end while
- r = (*r).next;
- }