嵌入式-链表尾插法插入
链表通过尾部插入
#include<stdio.h> #include<stdlib.h> struct Test { int data; struct Test * next; }; printfLink(struct Test * head) { while(head!=NULL) { printf("%d\n",head->data); head=head->next; } putchar('\n'); } struct Test * InsertEndNode(struct Test* head,struct Test * new) { struct Test * p=head; if(head==NULL) { head=new; return head; } while(p->next!=NULL) { p=p->next; } p->next=new; return head; } int main() { struct Test *head=(struct Test *)malloc(sizeof(struct Test)); head->data=1; struct Test new1={2,NULL}; struct Test new2={3,NULL}; struct Test new3={4,NULL}; struct Test new4={5,NULL}; struct Test * hp1=InsertEndNode(head,&new1); struct Test * hp2=InsertEndNode(hp1,&new2); struct Test * hp3=InsertEndNode(hp2,&new3); printfLink(hp3); return 0; }
输出结果:
1
2
3
4
4556
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!