#include <stdio.h> #include <stdlib.h> typedef int ElemType; typedef struct Lnode{ ElemType data;//数据域 struct Lnode* next;//指针域 }Lnode,*Linklist; void link_list_insert(Linklist &L){ L= (Linklist)malloc(sizeof(Lnode)); L->next=NULL; ElemType x; Linklist s,r=L; scanf("%d",&x); while (x!=9999){ s=(Linklist)malloc(sizeof(Lnode)); s->data=x; r->next=s; r=s; scanf("%d",&x); } r->next=NULL; } void printf_list(Linklist L){ L=L->next; while (L!=NULL){ printf("%d ",L->data); L=L->next; } } int main() { Linklist L; link_list_insert(L); printf_list(L); return 0; }
链表尾插法
最新推荐文章于 2024-07-12 18:56:03 发布