Removing dups from doubly linked list in C++ -


while dry run on page works fine, when tried run code in c++, throw exception "access violation reading locaiton", please me...

void dll::compress(){     node *temp1, *temp2, *dup;     temp1 = head;      while (temp1 && temp1->next)     {         temp2 = temp1->next;          while (temp2)         {             if (temp1->data == temp2->data)             {                 dup = temp2;                 if (temp2->next != null){                     temp2 = temp2->next;                     temp2->prev = temp1;                     temp1->next = temp2;                     delete dup;                 }                 else {                     temp1->next = null;                     delete temp2;                 }             }             else             {                 temp2 = temp2->next;             }         }         temp1 = temp1->next;     } } 

after delete temp2; keep looping, temp2 both non-null , invalid.

you need either set null or break out of loop.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -