插入结点..有问题.帮忙看一下...
#include<stdio.h>#include <stdlib.h>
struct node
{
int num;
struct node *next;
};
main()
{
int i,y;
struct node *head,*q,*p,*s;
for(i=0;i<5;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->num);
if(i==0)
{
head=p;
q=p;
p->next=NULL;
}
else
{
q->next=p;
q=p;
p->next=NULL;
}
}
p=head;
while(p)
{
printf("%d\t",p->num);
p=p->next;
}
printf("\n");
printf("input y \n");
s=(struct node *)malloc(sizeof(struct node));
scanf("%d",&y);
s->num=y;
s->next=NULL;
q=head;
while(p!=NULL && y<p->num)
{
q=p;
p=p->next;
}
s->next=p;
q->next=s;
p=head;
while(p)
{
printf("%d\t",p->num);
p=p->next;
}
}