带node
与不带node
单链表
不带头结点
![在这里插入图片描述](https://img-blog.csdnimg.cn/2e4e52d3d3484ce98ae3758e80e586ab.png)
带头结点
![在这里插入图片描述](https://img-blog.csdnimg.cn/d010c9dab67e4363b1a2d0c3901765fd.png)
示例代码
typedef struct Link{
int num;
Link *next;
}Inode;
class LinkedList{
Inode *CreateListByTrail(Inode *head,int n);
public Inode *LinkedList::CreateListByTrail(Inode *head,int n){
Inode *p=head;
for(int i=0;i<n;i++){
Inode *s==new Inode;
cin>>s-num;
s-next=p->next;
p-next=s;
p=s;
}
}
Inode **LinkedList::ReverseLink(INode *h){
Inode *headNext,*headPre;
headNext=h-next;
headPre=h;
h-next=null;
while(headNext){
Inode *temp=headNext->nest;
headNext->next=headPre;
headPre=headNext;
if(temp=null){
h=headPre;
}
headNext=temp;
}
return h;
}
}