I'm having trouble deleting multiple items from a list.
I need to ask the user how many numbers they want to delete from the top of the list, then delete them.
This is what I have got:
bool LinkedList::deleteFirstN(int N)
{
nodePtr currPtr;
for(int i = 0; i < N; i++)
{
if(N > size())
{
return false;
}
currPtr = head;
head = head->next;
currPtr->next = NULL;
delete currPtr;
}
return true;
}
this is the first time i've done this so if anyone could help I would be thankful.
I need to ask the user how many numbers they want to delete from the top of the list, then delete them.
This is what I have got:
bool LinkedList::deleteFirstN(int N)
{
nodePtr currPtr;
for(int i = 0; i < N; i++)
{
if(N > size())
{
return false;
}
currPtr = head;
head = head->next;
currPtr->next = NULL;
delete currPtr;
}
return true;
}
this is the first time i've done this so if anyone could help I would be thankful.