求助《链表结点插入》
帮忙讲解下结点插入时指针的移动过程!#include<stdio.h>
#include<stdlib.h>
#define NEW (SLIST *)malloc(sizeof(SLIST))
typedef struct node
{
int date;
struct node *next;
}SLIST;
SLIST *creat_slist()
{
SLIST *p,*r,*s;
int c;
p=NEW;
r=p;
printf("请输入数字当输入-1是停止输入!\n");
scanf("%d",&c);
while(c!=-1)
{
s=NEW;
s->date=c;
r->next=s;
r=s;
scanf("%d",&c);
}
r->next='\0';
return p;
}
void print_slist(SLIST *h)
{
SLIST *p;
p=h->next;
if(p=='\0') printf("link_slist is null!\n");
else
{
printf("head");
do
{printf("->%d",p->date);
p=p->next;
}while(p!='\0');
printf("end\n");
}
}
void insert_slist(SLIST *head,int x,int y)
{
SLIST *p,*q,*s;
s=NEW;
s->date=y;
p=head;
q=head->next;
while(q!='\0'&&q->date!=x)
{ p=q;q=q->next;}
s->next=q; /*请帮忙讲解下这里指针的移动过程*/
p->next=s;
}
void main()
{
SLIST *head;
int x,y;
printf("请输入查找数;\n");
scanf("%d",&x);
printf("请输入要插入的数:\n");
scanf("%d",&y);
head=creat_slist();
print_slist(head);
insert_slist(head,x,y);
print_slist(head);
}