k2k 5 Posting Whiz

Can anyone point out what is wrong with this function?

suppose I have a linklist which has already been populated with 100 nodes containing objects and linking from one to another. The object contain id, lastname, firstname... and I need to find a specific id and delete that node. (basically linking the node before the targetDeleteNode to the node after the targetDeleteNode...

template< typename NODETYPE >
void List< NODETYPE >::remove() const
{
	int targetID;
	cout<<"please enter the id you try to delete"<<endl;
	cin>>targetID;

ListNode< NODETYPE > *currentPtr= firstPtr;

while (currentPtr != 0 ) // get element data
{

	int tid = (*currentPtr->data).getID();

	if(tid == targetID)
	{
		
		ListNode<NODETYPE> *scanPtr = firstPtr;      // make a new scanPtr and initial it to be the firstPtr
		
		while(scanPtr!=0)
		{
			if(scanPtr->nextPtr== currentPtr)       // check from the firstPtr if its link is the targetPtr
			{
				scanPtr->nextPtr = currentPtr->nextPtr;   //if so, set the ptr has targetPtr as its nextPtr, 's next ptr the targetPtr's nextPtr
				currentPtr->nextPtr = scanPtr;             // make the scanPtr the targetPtr's nextPtr
			}

			
			scanPtr->nextPtr;

		}
		
		
		
	}

	currentPtr = currentPtr->nextPtr;

} // end while
cout<<"successfully remove target id"<<endl;
} // end function remove
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.