求大神, c++的问题
bool List::GetElem(int i, Node *pNode)
{
if (i < 0 || i >= m_iLength)
{
return false;
}
Node *currentNode = m_pList;
Node *currentNodeBefore = NULL;
for (int k = 0; k <= i; k++)
{
currentNodeBefore = currentNode;
currentNode = currentNode->next;
}
}
没写完, 链表, 为什么要加一个临时结点currentNodeBefore 直接currentNode = currentNode->next 循环到第i个位置不就行了, 干嘛多此一举