#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
int data;
struct Node* next;
}Node;
Node* creat(int Array[]){
Node *p,*pre,*head;
head=(Node*)malloc(sizeof(Node));
head->next=NULL;
pre=head;
for(int i=0;i<5;i++){
p=(Node*)malloc(sizeof(Node));
p->data=Array[i];
head->next=p;
head=head->next;
}
head->next=NULL;
return pre;
//尾插法
}
int main(){
int Array[5]={5,3,6,1,2};
Node* L=creat(Array);
L=L->next;
while(L!=NULL){
printf("%d ",L->data);
L=L->next;
}
return 0;
}
在晴神笔记基础上使用头插法尾插法。