hey, i am making a link list for a sort of ranking system, much like that in counter strike, the problem i am having is that when i go 2 delete an element the program crashes and i cant figure out wat is wrong with it.
I have the adding elements to the list working fine, just the deleting bit.
Iterator List::erase(Iterator pos)
{
Iterator iter;
assert(iter.location != NULL);
Node* remove = iter.location;
Node* before = remove->backward;
Node* after = remove->forward;
if (remove == first)
{
first = after;
}else
{
before->forward = after;
}
if (remove == last)
{
last = before;
}else
{
after->backward = before;
delete remove;
}
Iterator i;
return i;
}
thats the delete function for the iterator.
here is the main where the list is created "Note this is just test data"
List gavan;
gavan.send_back("test1");
gavan.send_back("test1");
gavan.send_back("test1");
gavan.send_back("test1");
gavan.send_back("test1");
gavan.send_back("test1");
gavan.send_back("test1");
gavan.insert(gavan.begin(),"hello");
gavan.erase(gavan.begin());
here is the begin function:
Iterator List::begin()
{
Iterator iter;
iter.position = first;
iter.last = last;
return iter;
}
hmzzz yeah when i try and delete an element the windows error reporting tool pops up, just wondering if any 1 can help.
Thankz very much in advance
[Edited by - Twinsen2 on July 30, 2005 10:42:34 PM]