#include<stdio.h>

#include<stdlib.h>

#define N 9

typedef struct node{ //声明结构体类型

int data;

struct node * next;

}ElemSN;

ElemSN * Createlink(int a[],int n) {

int i;

ElemSN * h=NULL,* tail, * p; // h :头指针 tail : 尾指针 p : 指向新建的node指针

for( i=0;i<N;i++){

p=(ElemSN *)malloc(sizeof(ElemSN)); // 创建node

p->data =a[i];

p->next=NULL;

if(!h) // 头指针为空,头指针 尾指针 新建指针 3个指向同一个node的ElemSN类型的指针

h=tail=p;

else //头指针不空

tail=tail->next=p; //新建的node给尾指针指针域,然后尾指针移动当前node

}

return h;

}

void printlink(ElemSN * h) { //打印输出函数

ElemSN * p;

for(p=h;p;p=p->next){

printf("%d\n",p->data);

}

int main(void){

int a[N]={1,2,3,4,5,6,7,8,9};

ElemSN * head=NULL;

head=Createlink(a,9);

printlink(head);

}