Inserting a Node in a Linked List

I have a double linked list that currently consists of a single node (it's a string with "two" as its data). Now, I want to insert a new node at the front of this list to create a two node list, but I don't know how to make this work.

First, here is the function inside a template file:

1
2
3
4
void dlist_head_insert(D_Node<Item> *&head_ptr, D_Node<Item> *&tail_ptr, const Item& entry) 
{
  head_ptr = new D_Node<Item>(entry, head_ptr, tail_ptr);
}


I think that part is more or less correct. But this book never really makes it clear how to actually call this function. From main(), I tried:

dlist_head_insert(head_ptr, tail_ptr, "one")

I get quite a few compilation errors, so clearly I don't understand what I am doing. Can anybody help?

Thanks.
Last edited on
Post some more code. How is head_ptr and tail_ptr declared?
Topic archived. No new replies allowed.