新手学数据结构中删除节点出现问题了,求教
#include<stdio.h>struct Qi
{
int num;
struct Qi *next;
};
main()
{
struct Qi a,b,c,d,*L,*p,q,*j;
a.num=1;
b.num=2;
c.num=3;
d.num=4;
L=&a;
a.next=&b;
b.next=&c;
c.next=&d;
d.next=NULL;
p=L;
int i=0;
int n;
printf("what do you want delete:");
scanf("%d",&n);
do
{ printf("%d\n",p->num);
p=p->next;
if(i==n)
{
q=p->num;//这里好像有问题?
p->next=p->next->next;
};
i++;
}while(p!=NULL);
i=0;
while(P!=MULL)
{
p=p->next;
i++;
}
printf("number is %d \n",i);
printf("%d \n",q);
return 0;
}
这是静态单链表,我想删除其中的某一个节点,但是老出错!