#include<stdio.h> #include<stdlib.h> typedef struct LinkList { int number; struct LinkList *next; }*LinkList,node; LinkList CreatList(LinkList head,int n); void print(LinkList head); int main(void) { LinkList head=NULL,p=NULL; for(int i=0;i<10;i++){ head = CreatList(head,i); } print(head); for(int i =0;i<10;i++) p = p->next; printf("%p\n",p); } LinkList CreatList(LinkList head,int n) { LinkList p=NULL,pr=head; p=(LinkList)malloc(sizeof(node)); if(p==NULL){ printf("error"); exit(1); } if(head==NULL){ head = p; } else{ while(pr->next!=NULL){ pr=pr->next; } pr->next=p; p->number=n; } return head; } void print(LinkList head) { LinkList p=head; p=p->next; while(p!=NULL){ printf("%3d",p->number); p=p->next; } printf("\n"); }
原文:https://www.cnblogs.com/ghc000/p/14726696.html