十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
if中可以賦值給head的理由很簡單。

清澗網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)公司成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
因?yàn)?if(PTScount(head) == 0)
if判斷的就是看它是不是 第一個(gè)元素。
如果是第一個(gè)元素,自然直接將ins賦值給head。
head所代表的就是第一個(gè)元素。
如果到了else這里,那么很明顯就不是第一個(gè)元素了。
那這個(gè)時(shí)候肯定就不可以直接復(fù)制給head了呀,因?yàn)閔ead可是代表第一個(gè)元素呀。
所以,你這是肯定改不了的。
//定義鏈表結(jié)點(diǎn),包括學(xué)號,姓名,和指向下一結(jié)點(diǎn)的指針
struct node {
int num;
int name;
struct node *next;
}*linklist
// 當(dāng)需要一個(gè)結(jié)點(diǎn)的時(shí)候,就為新結(jié)點(diǎn)分配內(nèi)存空間
linklist p;
p=(linklist)malloc(sizeof(struct node));
//結(jié)點(diǎn)成員賦值
num=2004;
name=Tom;
next=NULL;
//然后用鏈表的指針指向該結(jié)點(diǎn)p就可以了
//比如有一個(gè)指針r指向鏈表的尾部,可以用以下方法將新結(jié)點(diǎn)加如鏈表中
r-next=p;
#includeiostream
using?namespace?std;
class?Node?{
public:
int?data;
Node*?next;
Node(int?_data)?{
data?=?_data;
next?=?NULL;
}
};
class?LinkList?{
private:
Node*?head;
public:
LinkList()?{
head?=?NULL;
}
void?insert(Node?*node,?int?index)?{
if?(head?==?NULL)?{
head?=?node;
return;
}
if?(index?==?0)?{
node-next?=?head;
head?=?node;
return;
}
Node?*current_node?=?head;
int?count?=?0;
while?(current_node-next?!=?NULL??count??index?-?1)?{
current_node?=?current_node-next;
count++;
}
if?(count?==?index?-?1)?{
node-next?=?current_node-next;
current_node-next?=?node;
}
}
void?output()?{
if?(head?==?NULL)?{
return;
}
Node?*current_node?=?head;
while?(current_node?!=?NULL)?{
cout??current_node-data??"?";
current_node?=?current_node-next;
}
cout??endl;
}
void?delete_node(int?index)?{
if?(head?==?NULL)?{
return;
}
Node?*current_node?=?head;
int?count?=?0;
if?(index?==?0)?{
head?=?head-next;
delete?current_node;
return;
}
while?(current_node-next?!=?NULL??count??index?-1)?{
current_node?=?current_node-next;
count++;
}
if?(count?==?index?-?1??current_node-next?!=?NULL)?{
Node?*delete_node?=?current_node-next;
current_node-next?=?delete_node-next;
delete?delete_node;
}
}
void?reverse(){
if(head?==?NULL){
return;
}
Node?*next_node,*current_node;
current_node?=?head-next;
head-next?=?NULL;
while(current_node?!=?NULL){
next_node?=?current_node-next;
current_node-next?=?head;
head?=?current_node;
current_node?=?next_node;
}
}
};
int?main()?{
LinkList?linklist;
for?(int?i?=?1;?i?=?10;?i++)?{
Node?*node?=?new?Node(i);
linklist.insert(node,?i?-?1);
}
linklist.output();
linklist.delete_node(3);
linklist.output();
linklist.reverse();
linklist.output();
return?0;
}