#include "stdio.h" #include "stdlib.h" typedef struct List { int data; struct List *next; //指针域 }List; void HeadCreatList (List *L) //头插法建立链表 { List *s; L->next=NULL; for (int i=0;i<10;i++) { s=(struct List*)malloc(sizeof(struct List)); s->data=i; s->next=L->next; //将L指向的地址赋值给S; L->next=s; } } void TailCreatList(List *L) //尾插法建立链表 { List *s,*r; r=L; for (int i=0;i<10;i++) { s=(struct List*)malloc(sizeof(struct List)); s->data=i; r->next=s; r=s; } r->next=NULL; } void DisPlay(List *L) { List *p=L->next; while(p!=NULL) { printf ("%d ",p->data); p=p->next; } printf("\n"); } int main () { List *L1,*L2; L1=(struct List*)malloc(sizeof(struct List)); L2=(struct List*)malloc(sizeof(struct List)); HeadCreatList(L1); DisPlay(L1); TailCreatList(L2); DisPlay(L2); }
链表头插尾插
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
简单的尾插法实现单链表
尾插法建立单链表
结点 头结点 链表 -
单链表尾插法
顺便练习下数据结构,今天的题目是:无头结点的,单链表尾插法。
数据结构 单链表 尾插法 -
HashMap 链表插入方式 → 头插为何改成尾插 ?
数据结构 对 HashMap 的底层数据结构,相信大家都有所了解,不同的版本,底层数据结构会有所不
链表 数据结构 java redis hashmap -
单链表的头插、尾插、删除、合并等操作
单链表的头插、尾插、删除、合并等操作
键盘 单链表 元素