M
mathon
hello,
i thought i create a new topic for that because i deal with a certain
problem. I have implemented all methods for a LinkdeList (for my
sequence class) and tested all correct. Now i only have problems with
the remove method to delete a certain node from the list. my remove
method looks like this:
So I used three cases - when the node should be deleted from the middle
of the list, when the node which should be deleted is at the end of the
list and when there is only one more node in the list. Unfortunately
the second case causes an error where the last node of the list should
be deleted:
The error occurs at the following statement:
delete cursor;
A popup window is displayed with the following error message:
Fehler:
Debug Assertion Failed!
Program: ...
File: dbgdel.cpp
Line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information on how your program can cause an assertion failure, see
the Visual C++ documentation on asserts.
Why can't I use the delete cursor statement to delete the last node?
(the cursor points to the last node) - has anybody an idea how to
define that correctly. The specification says when the last node is
deleted the cursor pointer should be then null again, thats why i tried
it with delete cursor.
matti
PS: The cursor pointer points to the actual node of the list, the
precursor to the previous node and the tail_ptr points every time to
the last node.
i thought i create a new topic for that because i deal with a certain
problem. I have implemented all methods for a LinkdeList (for my
sequence class) and tested all correct. Now i only have problems with
the remove method to delete a certain node from the list. my remove
method looks like this:
Code:
void sequence::remove_current( )
{
if(!(is_item()))
return;
node *target_ptr;
if(cursor != tail_ptr && many_nodes > 1)
{
cout << "Cursor != tail_ptr" << endl;
target_ptr = cursor;
cursor = cursor->link();
precursor->set_link(cursor);
delete target_ptr;
node* cursor1;
node* precursor1;
for(cursor1 = head_ptr; cursor1 != NULL; cursor1 = cursor1->link())
{
precursor1 = cursor1;
}
tail_ptr = precursor1;
--many_nodes;
return;
}
else if(cursor == tail_ptr)
{
delete cursor;
--many_nodes;
return;
}
else if (many_nodes == 1)
{
list_head_remove(head_ptr);
start();
--many_nodes;
return;
}
}
So I used three cases - when the node should be deleted from the middle
of the list, when the node which should be deleted is at the end of the
list and when there is only one more node in the list. Unfortunately
the second case causes an error where the last node of the list should
be deleted:
The error occurs at the following statement:
delete cursor;
A popup window is displayed with the following error message:
Fehler:
Debug Assertion Failed!
Program: ...
File: dbgdel.cpp
Line: 52
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
For information on how your program can cause an assertion failure, see
the Visual C++ documentation on asserts.
Why can't I use the delete cursor statement to delete the last node?
(the cursor points to the last node) - has anybody an idea how to
define that correctly. The specification says when the last node is
deleted the cursor pointer should be then null again, thats why i tried
it with delete cursor.
matti
PS: The cursor pointer points to the actual node of the list, the
precursor to the previous node and the tail_ptr points every time to
the last node.