ATEM0那個方法確實可以不用定義currentNodeBefore,但是你有沒有想過這樣就無法delete需要刪除的node了?
2019-03-13
最新回答 / Cyber丶Kaka
我的理解是這樣的:因為即使有的位置沒有賦值,但還算線性表的內容,只不過它們的內容為空值,但它們仍然是有索引的.這里i的作用只是要它滿足線性表的索引即可,如果寫成i<m_iLength,可能程序運行并沒有問題,但是從邏輯上講i并沒有遍歷到所有的線性表索引,這個循環(huán)是不完整的.
2019-03-10
最新回答 / Alex_ZM
除頭結點以外的結點已經(jīng)被刪除了,此時剩下的頭結點的指針域沒有一個確定的指向,如果設成NULL的話,就像相當于回到單鏈表的最初始狀態(tài)。
2019-01-01
Node *currentNode=m_pList;
Node *currentNodeBefore=nullptr;
for(int a=0;a<i;a++)
currentNode=currentNode->next;
currentNodeBefore=currentNode;
currentNode=currentNode->next;
currentNodeBefore->next=currentNode->next;
pNode->data=currentNode->data;
這么寫是一種更高效的循環(huán)。
Node *currentNodeBefore=nullptr;
for(int a=0;a<i;a++)
currentNode=currentNode->next;
currentNodeBefore=currentNode;
currentNode=currentNode->next;
currentNodeBefore->next=currentNode->next;
pNode->data=currentNode->data;
這么寫是一種更高效的循環(huán)。
2018-12-23
void DeleteContact(List *pList)
{
Node node;
Person person;
cout << "Please input name:" << endl;
cin >> person.name;
cout << "Please input phone number:" << endl;
cin >> person.phone;
node.data = person;
int num = 0;
num = pList->LocatedElem(&node);
pList->ListDelete(num, &node);
}
{
Node node;
Person person;
cout << "Please input name:" << endl;
cin >> person.name;
cout << "Please input phone number:" << endl;
cin >> person.phone;
node.data = person;
int num = 0;
num = pList->LocatedElem(&node);
pList->ListDelete(num, &node);
}
2018-12-18