el = pTemp->next;
pTemp->next = pDel->next;
delete pDel;
m_listLength--;
return true;
}
//得到指定位置节点的指针。
bool LinkList::GetNode(int position, LNode **node) {
LNode *pTemp = NULL;
int curPos = -1;
pTemp = m_pList;
while (pTemp != NULL) {
curPos++;
if (curPos == position)
break;
pTemp = pTemp->next;
}
if (curPos != position) {
return false;
}
*node = pTemp;
return true;
}
//定位与指定数据相等的数据节点。
//如果在当前链表中已经存在该数据则返回该数据节点的索引号。
//若不存在这样的节点则返回0。
//节点索引从0开始到listLength。
int LinkList::LocateElem(int elem) {
LNode *pTemp = NULL;
int curIndex = 1;
pTemp = m_pList->next;
while ((pTemp != NULL) && (pTemp->data != elem)) {
pTemp = pTemp->next;
curIndex++;
}
if (pTemp == NULL) {
return 0;
}
return curIndex;
}
/*
int main(){
LinkList l;
l.InsertNode(1, 10);
l.InsertNode(2, 20);
l.InsertNode(3, 30);
l.InsertNode(4, 40);
cout << l.GetLength() << endl;
int dataTemp = 0;
for (int i = 1; i <= l.GetLength(); i++) {
l.GetNodeData(i, dataTemp);
cout << dataTemp << endl;
}
if (l.SetNodeData(3, 50)) {
cout <<"DONE/n";
} else {
cout << "Failed/n";
}
for (i = 1; i <= l.GetLength(); i++) {
l.GetNodeData(i, dataTemp);
cout << dataTemp << endl;
}
if (l.DeleteNode(4)) {
cout <<"DONE/n";
} else {
cout << "Failed/n";
}
for (i = 1; i <= l.GetLength(); i++) {
l.GetNodeData(i, dataTemp);
cout << dataTemp << endl;
}
cout << l.LocateElem(50) << endl;
return 0;
}
*/