填空题

将a、b、c三个结点链成一个单向链表,并给各结点的数据域赋值,函数fun的作用是:累加链表结点数据域中的数据作为函数值返回。


请改正程序中的错误,使它能得出正确的结果。

#include <stdio.h>

#include <stdlib.h>

typedef struct list

{

    int data;

    struct list *next;

} LIST;

int fun(LIST *h)

{

    LIST *p;

    int t=0;

    p=h;

    /**********found**********/

    while(*p)

    {

        /**********found**********/

        t=t+p.data;

        p=(*p).next;

    }

    return  t;

}

main()

{

    LIST a,b,c,*h; 

    a.data=34;

    b.data=51;

    c.data=87;

    c.next='\0';

    h=&a;

    a.next=&b;

    b.next=&c;

    printf("总和 = %d\n",fun(h));

    system("pause");

}

赣ICP备20007335号-2