tl2655600 发表于 2009-3-25 23:24:47

c语言有关链表问题

struct student
{
        int num;
        char name;
        char sex;
        float hight;
        float weight;
        struct student *next;
};
void Add(struct student *head,int *n)
{
        int *m=n;
        int number;
        struct student *p1,*p2,*p0;
        if(head==0)
        {
                head=(struct student *)malloc(sizeof(struct student));
                if(!head)
                {
                        printf("\nError");
                        return;
                }
                else
                {
                        printf("\nSet Success");
                        *m=*m+1;
                }
        }
    p1=p2=head;
        printf("\ninput plus number:\n");
        scanf("%d",&number);
    for(int i=0;i<*m;i++)
        {
                p1=p2;
                p2=p1->next;
                if(p1->num==number||p2->num==number)
                {
                        printf("\nSorry!have it now");
                        break;
                }
                else if(p1->num<number&&p2->num>number)
                {
                        p1->next=p0=(struct student *)malloc(sizeof(struct student));
                        scanf("%d %s %c %f %f",p1);
                        printf("\nRealy?(Y/N)");
                        char key=getchar();
                        if(key=='y')
                        {
                                p0->next=p2;
                        }
                }
        }
}这一段调试时没有错,就是运行不起来
页: [1]
查看完整版本: c语言有关链表问题