|
发表于 2013-3-26 18:53:19
|
显示全部楼层
del函数里面错误挺多,改过的代码:
- #include <stdio.h>
- #include <stdlib.h>
- struct lian
- {
- int data;
- struct lian *next;
- };
- typedef struct lian LIST;
- LIST *getdat()
- {
- LIST *h,*s,*p;
- int x;
- h=(LIST *)malloc(sizeof(LIST));
- p=h;
- scanf("%d",&x);
- while(x!=-1)
- {
- p->data=x;
- s=(LIST *)malloc(sizeof(LIST));
- p->next=s;
- p=s;
- scanf("%d",&x);
- }
- p->next=NULL;
- return h;
- }
- void printdat(LIST *h)
- {
-
- printf("HEAD");
- while(h->next!=NULL)
- {
- printf("->%d",h->data);
- h=h->next;
- }
-
- printf ("END\n");
- }
- void deldat (LIST **h) //运行到这儿就程序出错,高手帮忙看下
- {
- LIST *p;
- int x;
- scanf("%d",&x);
- p=*h;
- while (p->data!=x&&p->next!=NULL)
- {
- p=p->next;
- }
- if (p->data==x)
- {
- p->data = p->next->data;
- p->next = p->next->next;
- }
- }
- int main ()
- {
- LIST *head;
- head=getdat();
- printdat(head);
- deldat(&head);
- printdat(head);
- flushall();
- getchar();
- return 0;
- }
复制代码
|
|