注册 登录
编程论坛 新人交流区

菜鸟提问:关于单链表的删除问题

网痘 发布于 2007-11-06 09:40, 301 次点击

#include "alloc.h"
#include "stdio.h"
struct node
{int data;
struct node *next;
};
int a;int b;int j=0;
main()
{int data;
struct node *head;
struct node *p,*q,*s,*h,*m;
head=(struct node *)malloc(sizeof(struct node));
clrscr();
printf("please input a number:");
scanf("%d",&head->data);
p=head;
q=head;
while(p->data!=-999)
{printf("\nplease input the next number or end with -999.");
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
q->next=p;
q=p;
}
q->next=NULL;
p=head;
while(p->next!=NULL)
{printf("%d",p->data);
p=p->next;
}
getch();

printf("\nplease input a:");
scanf("%d",&a);
printf("\nplease input b:");
scanf("%d",&b);

while(s->next && (s->data<a||s->data>b))
{s=head,m=head;
m=s;s=s->next;}

while(s->next && a<s->data && s->data<b )


{h=m->next;m->next=h->next;free(h);
s=m->next;

}
m=head;
while(m->next!=NULL)
{printf("%d",m->data);m=m->next;}

}
这是个单链表的删除问题,可是为什么我的程序从循环开始的时候不执行?

1 回复
#2
网痘2007-11-06 10:44
自己解决了。。。
1