wintc 中特别奇怪程序没有执行
#include<stdio.h>#include<malloc.h>
struct link
{
int data;
struct link *next;
};
struct link* creat()
{
struct link *head,*tail,*p;
head=tail=NULL;
printf("please input one number:\n");
p=(struct link*)malloc(sizeof(struct link));
p->next=NULL;
scanf("%d",&p->data);
while(p->data!=0)
{
if(head==NULL)head=tail=p;
else
{
tail->next=p;
tail=p;
}
p=(struct link*)malloc(sizeof(struct link));
p->next=NULL;
scanf("%d",&p->data);
}
return(head);
}
output(struct link* head)
{
int k=0;
struct link *p;
p=head;
while(p!=NULL)
{ k++;
printf("the %dTH is %d\n",k,p->data);
p=p->next;
}
}
struct link* comein(struct link* head,struct link *newdata)
{
struct link *p1,*p2;
p1=head;
while(p1!=NULL&p1->data>=newdata->data)
{
p2=p1;
p1=p1->next;
}
if(!(p1->data>=newdata->data))
{
if(p1==head)
{
head=newdata;
newdata->next=p1;
}
else
{
p2->next=newdata;
newdata->next=p1;
}
}
else
{
p1->next=newdata;
newdata->next=NULL;
}
return(head);
}
struct link *del(struct link *head,int k)
{
struct link *p1,*p2;
p1=head;
while(p1!=NULL&&p1->data!=k)
{
p2=p1;
p1=p1->next;
}
if(p1->data==k)
{
if(p1==head) head=p1->next;
else
{
p2->next=p1->next;
}
}
return(head);
}
main()
{
struct link *head,*p;
int k;
printf("THE fellow is creat test:\n");
head=creat();
output(head);
printf("THE fellow is COMEIN test:\n");
printf("please input a newdata:\n");
p=(struct link *)malloc(sizeof(struct link));
scanf("%d",&p->data);
p->next=NULL;
comein(head,p) ;
output(comein(head,p));
printf("the fellow is DEL test:\n");/ *这里没有执行*/
printf("please input DEL number:");/*这里没有执行*/
scanf("%d",&k);/*这里没有执行*/
output(del(comein(head,p),k));/*这里没有执行*/
getch();
}