I'm having trouble getting my delete function to work for a singly linked list. If I try to delete anything other than the entire list, it deletes everything up to that node.
I know there is something wrong with it, but I can't tell what it is. I would like to structure it so that it can delete any one node in the list, then I'd like to be able to print the list to the screen. btw, insert and print work fine, just not the delete. Here is the code
bool list::del(Contributor Del)
{
Contributor infoIn=Del;
node *pprev= plist;
node *ptrav= plist;
if (empty()) //empty list
{
cout<<"The list is empty "<<endl;
}
if (pprev==ptrav) //list beginning
{
plist = ptrav->next; //sends plist to next node
delete ptrav; //delete Node
}
while((ptrav!=NULL) && (ptrav->infoIn!=Del))
{
pprev= ptrav;
ptrav= ptrav->next;
}
if (pprev==ptrav)
return false;
else
if(pprev==NULL)
{
plist= plist->next;
delete ptrav;
}
else
{
pprev->next =ptrav->next;
delete ptrav;
}
return true;
}