Yes, you're right. It should be: newnode->next->prev = newnode;
instead of newnode->next->prev = node_to_insert_after;
Aside from this, I'm not sure whether this is a typo but where you should have a }
, you have {
. For example, your struct definition should be:
struct node {
int value;
struct node* next;
struct node* prev;
};
What I must ask is: why are you asking this question? Why not write some tests for yourself to see if things work rather than asking on stack overflow? For example, you could write a function which prints the list:
void print_list(struct node *head) {
for(struct node *cur = head; cur != NULL; cur = cur->next) {
printf("%d ", cur->value);
}
printf("\n");
}
Then you could use your insert functions and print the list to see if it works.