这个程序和视频中六分五十二秒的程序相同,可为什么运行不了呢
冷静 资深达人 2015-09-09 18:10:13
2129 1 0

#include <stdio.h>

#include <stdlib.h>

struct Node

{

    int age;

    struct Node *next;

};

struct Node *creat(int n)

{

    struct Node *p,*pnew,*pold;

    int i;

    for(i=0;i<n;i++)

    {

        pnew=(struct Node*)malloc(sizeof(struct Node));

        scanf("%d",&pnew->age);

        pnew->next=NULL;

        if(i==0)

            p=pold=pnew;

        else

        {

            pold->next=pnew;

            pold=pnew;

        }

        return p;

     }

}

int main()

{

    struct Node *header=NULL;

    header=creat(3);

    printf("%d\n",header->age);

    printf("%d\n",header->next->age);

    printf("%d\n",header->next->next->age);

}


问题来自: 线性链表

共 1 个回答

    嘿嘿大人 一代宗师 3171天前

    最后的大括号打错地方了

    #include <stdio.h>


    #include <stdlib.h>


    struct Node


    {


        int age;


        struct Node *next;


    };


    struct Node *creat(int n)


    {


        struct Node *p,*pnew,*pold;


        int i;


        for(i=0;i<n;i++)


        {


            pnew=(struct Node*)malloc(sizeof(struct Node));


            scanf("%d",&pnew->age);


            pnew->next=NULL;


            if(i==0)


                p=pold=pnew;


            else


            {


                pold->next=pnew;


                pold=pnew;


    }


            return p;


         }




    int main()


    {


        struct Node *header=NULL;


        header=creat(3);


        printf("%d\n",header->age);


        printf("%d\n",header->next->age);


        printf("%d\n",header->next->next->age);


    }


您还没有登录,所以不能回复该问题
我要回复

  • 0

    点赞

  • 扫一扫分享朋友圈

    二维码

  • 分享

相关问题