Hey all i am trying to delete a set number of items in a linked list. Here is the code for delete my item.
Code:
void unorderedLinkedList<Type>::deleteNode(const Type& deleteItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
bool found;
found = false;
trailCurrent = first; //set trailCurrent to point
//to the first node
current = first->link; //set current to point to
//the second node
while (current != NULL && !found)
{
if (current->info != deleteItem)
{
trailCurrent = current;
current = current-> link;
}
else
found = true;
}//end while
if (found) //Case 3; if found, delete the node
{
trailCurrent->link = current->link;
count--;
if (last == current) //node to be deleted
//was the last node
last = trailCurrent; //update the value
//of last
delete current; //delete the node from the list
}
else
cout << "The item to be deleted is not in "
<< "the list." << endl;
}//end else
}//end deleteNode
Right now it only deletes the 1 string i pass to it "deleteItem". However, i wish to delete the next 8 blocks after the "deleteItem".
Say i have this in the list right now.
bob barker is pretty old but still seems to get all the ladies
Now the user would pick "bob" and with the code above, would delete "bob" but leave everything else. I wish to take out "bob, barker, is, pretty, old, but, still, seems, to" when the code above executes.
Like so:
bob (delete)
barker (delete)
is (delete)
pretty (delete)
old (delete)
but (delete)
still (delete)
seems (delete)
to (delete)
get
all
the
ladies
I'm unsure on how to go about doing that. Any help would be great!
David