出于某种原因,我从列表中间删除节点的功能是删除第一个节点而不是用户指定的节点。这是我的功能:
template< class NODETYPE >
bool List< NODETYPE >::removeMiddle( NODETYPE &value, int i )
{
ListNode <NODETYPE> * tempPtr = firstPtr;
int counter=1;
if ( isEmpty() )
return false;
if (i <= 0)
return false;
while (tempPtr != 0 && counter < i){
counter++;
if ( firstPtr == lastPtr )
firstPtr = lastPtr = 0;
else
firstPtr = firstPtr->nextPtr;
if (counter == i){
value = tempPtr->data; // data being removed
delete tempPtr;
}
}
return true;
RecordCounter--;
}
谁能帮我指出正确的方向?