视频讲解单链表2BV17s411N78s
小甲鱼是怎样把tali定位到链表的尾部的???void addBook(struct Book **library)
{
struct Book *book,*tail;
book = (struct Book *)malloc(sizeof(struct Book));
if(book==NULL)
{
printf("动态内存分配失败");
exit(1);
}
getIput(book);
if(*library!=NULL)
{
tail->next = book;
book->next = NULL;
}
else
{
*library = book;
book->next=NULL;
}
tail = book; tail->next = book;
book->next = NULL;
book为尾结点,tail->next = book;让tail指向尾结点的前一个
book->next = NULL;让book重新指向尾结点(此时插入了新元素)
页:
[1]