Q:

Is this a proper way to insert a node after the first for a doubly linked list?

NodePtr p = new Node(id, age, email)
p->prev = top;
p->next = top->next;
top->next = p;
top->next->prev = p;

I am trying to insert node p after the first node. 
I am trying to teach myself how to use doubly linked lists. When I draw it out, it looks like it would work. I just wanted confirmation if this is correct. If this is not correct, how should I fix it?

A:

Your implementation doesn't work.
top->next = p; // top->next is now p
top->next->prev = p; // p->prev is now p, oops

Swap those two lines, and it'll be correct.
top->next->prev = p; // top->next->prev is now p
top->next = p; // top->next is now p

