看到我请让我去努力 提问:英雄哥我最近在学链表数据结构但是我很困惑对于链表相连。
#include<iostream>
#include<cstring>
using namespace std;
struct st_name{
int num;
string name;
struct st_name *next;
};
int main(){
st_name* head=nullptr,*tail=nullptr,*tmp=nullptr;
tmp=new st_name({1,"我是1",nullptr});
head=tail=tmp;
tmp=new st_name({2,"我是2",nullptr});
tail->next=tmp;
tail=tmp;
tmp=new st_name({3,"我是3",nullptr});
tail->next=tmp;
tail=tmp;
tmp=head;
while(tmp!=nullptr){
cout<<tmp->name<<" "<<tmp->next<<endl;
tmp=tmp->next;
}
while(head!=nullptr){
tmp=head;
head=head->next;
delete tmp;
}
}我的问题是为什么tmp->next->next可以呢?它的tmp->next不应该就是0吗.修改的不是tail->next吗为什么head可以也被影响
1、初始化链表指针:
- `st_name* head...