#include <stdio.h> #include <stdlib.h> #include<malloc.h> #define MAX 100 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ typedef int ElmType; typedef struct node{ ElmType data; struct node* next; }Node,*LinkedList; typedef enum {ERROR=-1,OK = 0} Status; LinkedList node_create(ElmType data){ LinkedList p=(LinkedList)malloc(sizeof(Node)); p->data=data; p->next=NULL; return p; } LinkedList Create(LinkedList head,int n){ LinkedList p=head; ElmType i; for(i=0;i<n;i++){ p->next=node_create(i); p=p->next; } return head; } Status list_print(LinkedList head){ if(head==NULL){ return ERROR; } ElmType a[MAX]; ElmType i=0; LinkedList p=head->next; for(i=0;i<MAX;i++){ a[i]=p->data; p=p->next; } for(i=MAX-1;i>=0;i--){ printf("%d\n",a[i]); } } int main(int argc, char *argv[]) { LinkedList head=node_create(0); //创造头节点 Create(head,MAX); //创造列表 list_print(head); //打印列表 free(head); return 0; }