【文章內(nèi)容簡介】
點 結(jié)點 n … 新結(jié)點 pNew pEnd head (a) 加入前 pNew=new node。 next next … data data 頭結(jié)點 結(jié)點 n … next data 結(jié)點 n+1 head (b) 加入后 pEndnext=pNew。 pEnd=pNew。 pEnd pNew ? 鏈表創(chuàng)建結(jié)束 next 0 next next … data data 頭結(jié)點 結(jié)點 n … 新結(jié)點 pNew pEnd head (a) 結(jié)束前 pNew=new node。 (b) 結(jié)束后 pEndnext=0; delete pNew。 next 0 … data data 頭結(jié)點 結(jié)點 n … pEnd head . 鏈 表的輸出 void ShowList(node* head) { if(head==0) { coutList is empty!endl。 return。 } node *temp=head。 cout now the items of list are: \n。 while(temp!=0){ cout tempdataendl。 temp=tempnext。 } } . 鏈 表某個結(jié)點的訪問 node* access(node* head,int n) { if(head==0) { coutList is empty!endl。 return 0。} node *temp。 temp=head。 for(int i=1。in。i++) { if(tempnext==0) { cout“要訪問的結(jié)點數(shù)大于鏈表的結(jié)點數(shù) .”?\n?。 return 0。 } temp=tempnext。 } return temp。 } . 統(tǒng)計 鏈 表結(jié)點的個數(shù) int node