标签:blog io for 2014 log size type ad
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
{
int data;
struct list *next;
}SLIST;
SLIST *creatlist(int *);
void outlist(SLIST *);
int fun(SLIST *h)
{
SLIST *p;int s=0;
p=h->next;
while(p)
{ s+=p->data;
p=p->next;
}
return s;
}
main()
{
SLIST *head;
int a[N]={268,87,45,32,91,16,20,12};
head=creatlist(a);outlist(head);
printf("\nsum=%d\n",fun(head));
}
SLIST *creatlist(int a[])
{
SLIST *h,*p,*q;int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0;i<N;i++)
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i];p->next=q;p=q;
}
p->next=NULL;
return h;
}
void outlist(SLIST *h)
{
SLIST *p;
p=h->next;
if(p==NULL)
printf("The list is NULL!\n");
else
{
printf("->%d",p->data);
p=p->next;
}
while(p!=NULL);
printf("->End\n");
}
没看懂 开学再看看标签:blog io for 2014 log size type ad
原文地址:http://blog.csdn.net/u013116579/article/details/38455139