Would this be the correct order to insert a new node at P into a doubly linked list before the the node pointed to cur. Thanks!
Code:P->Next = Cur; P->Before = Cur->Before; P->Before->Next = P; P->Next->Before = P;
Would this be the correct order to insert a new node at P into a doubly linked list before the the node pointed to cur. Thanks!
Code:P->Next = Cur; P->Before = Cur->Before; P->Before->Next = P; P->Next->Before = P;
In theory, yes, that's fine. In practice, you'll need to do a bit more checking (this is overly cautious, assuming Cur may be null):
Code:P->Next = Cur; if (Cur) { P->Before = Cur->Before; } else { P->Before = 0; } if (P->Before) { P->Before->Next = P; } if (P->Next) { P->Next->Before = P; }
My best code is written with the delete key.