Let me post this all since I've tried so many things that I don't even know which way is up.
First, what I am trying to do is to insert a new node in a double-linked list. In order to do that, I need to identify the node BEFORE the spot where I want to insert the new node. My list up to this point consists of integers {1,2,3,5,6}. I want to insert a {4} in the appropriate spot.
So, for now, I am focusing on returning that node (where the 3 is).
Here is the entirety of main():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int main()
{
//create a new list (single node)
D_Node<int> first(3, NULL, NULL);
D_Node<int> *head_ptr;
D_Node<int> *tail_ptr;
head_ptr = &first;
tail_ptr = &first;
//insert two new nodes at the end of a list
dlist_tail_insert(tail_ptr, 5);
dlist_tail_insert(tail_ptr, 6);
//insert two new nodes at the head of the list
dlist_head_insert(head_ptr, tail_ptr, 2);
dlist_head_insert(head_ptr, tail_ptr, 1);
//search the list for the node with 3 as its data_field
D_Node<int> previous_ptr(0, NULL, NULL);
previous_ptr->set_fore(dlist_search(head_ptr, 3));
}
| |
And my dlist_search function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
template <class Item>
D_Node<Item> dlist_search(D_Node<Item> *head_ptr, Item &target)
{
D_Node<Item> *cursor;
for (cursor = head_ptr; cursor != NULL; cursor = cursor->fore())
{
if (target == cursor->data_field())
{
return cursor;
}
}
return NULL;
}
| |
I'm getting a no matching function call on the dlist_search. I can tell that this logic isn't right, but I can't see how to change it. My ultimate goal is to capture this search result in the node called previous_ptr.
Thanks for helping. I'm banging my head against a wall.