#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include <stdio.h>
#define LEN sizeof(struct Node)
typedef struct Node{
int data;
struct Node * next;
}node;//定义结点的类型;
void createLink(node * head, int *a, int n){
head->next = NULL;
for (int i = 0; i < n; i++){
node * p = (node*)malloc(LEN);
p->data = a[i];
p->next = head->next;
head->next = p;
}
}
void pri_link(node *head){
node *p = (node *)malloc(LEN);
p= head->next;
while (p != NULL){
printf("%d\n", p->data);
p = p->next;
}
}
int main(){
int a[5] = { 1, 2, 3, 4, 5 };
node * head = (node *)malloc(LEN);
createLink(head, a, 5);
pri_link(head);
}
执行效果如下如图
?
|