news 2026/8/16 14:31:24

C语言链表2

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
C语言链表2
#include<stdio.h> #include<stdlib.h> struct node{ int date; struct node* next; }; struct node* creat(int info){ //创建一个节点 struct node* newnode=(struct node*)malloc(sizeof(struct node)); if(newnode==NULL){ printf("error\n"); exit(1); } newnode->date=info; newnode->next=NULL; return newnode; } void add(struct node** head, int info){ //在链尾接上节点 struct node* newnode=creat(info); if(*head==NULL){ *head =newnode; return; } struct node* now=*head;//当前指针不为空 while(now->next!=NULL){ now=now->next; } now->next=newnode; } void coutout(struct node* head){ //遍历链表输出 struct node* now=head; printf("following is the list:\n"); while(now!=NULL){ printf("%d ",now->date); now=now->next; } printf("\n"); } void freelist(struct node* head){ //释放内存 struct node* t; while(head!=NULL){ t=head; head=head->next; free(t); } } void insert(struct node* head,int k,int date){ //插入节点 if(head==NULL){ printf("empty\n"); return; } struct node* now=head; for(int i=1;i<k&&now!=NULL;i++){ now=now->next; } if(now==NULL){ printf("over the list\n"); return; } struct node* newnode=creat(date); newnode->next=now->next; now->next=newnode; } void deletenode(struct node** head,int k){ if(*head==NULL){ printf("the list is empty\n"); return; } struct node* now=*head; struct node* prev=NULL; for(int i=1;i<k&&now!=NULL;i++){ prev=now; now=now->next; } if(now==NULL){ printf("over the list\n"); return; } if(prev==NULL){ *head=now->next; }else{ prev->next=now->next; } free(now); } int main(){ struct node* head=NULL; int num; scanf("%d",&num); while(num--){ int t; scanf("%d",&t); add(&head,t); } coutout(head); freelist(head); }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/15 9:35:17

Kotaemon工单系统联动:Jira/ServiceNow操作

Kotaemon工单系统联动&#xff1a;Jira/ServiceNow操作 在现代企业IT运维的日常中&#xff0c;一个常见的场景是&#xff1a;某位员工发现会议室打印机无法连接&#xff0c;随即在协作工具里发了一条消息&#xff1a;“今天开会时投影连不上&#xff0c;谁帮忙看看&#xff1f;…

作者头像 李华
网站建设 2026/8/15 13:12:36

AI在智能物流路径规划与车辆调度中的实时优化应用

AI在智能物流路径规划与车辆调度中的实时优化应用 关键词:AI、智能物流、路径规划、车辆调度、实时优化 摘要:本文深入探讨了AI在智能物流路径规划与车辆调度实时优化中的应用。详细介绍了相关的核心概念、算法原理、数学模型,通过项目实战展示了代码实现及解读。同时,阐述…

作者头像 李华
网站建设 2026/8/15 12:32:07

Revit 200+新功能之“明周科技功能商店 AI推荐助手”

# 简介&#x1f3af; 开发背景与初衷随着我们 Revit 插件不断演进&#xff0c;用户在线提交的功能需求已接近 200 项&#xff0c;涵盖图纸生成、构件建模、参数赋值、数据统计、标高调整等多个方向。虽然我们已将这些功能模块化、面板化管理&#xff0c;但功能数量庞大后&#…

作者头像 李华
网站建设 2026/8/16 7:06:11

Kotaemon中的评分机制如何判断答案可靠性?

Kotaemon中的评分机制如何判断答案可靠性&#xff1f; 在企业级智能问答系统日益普及的今天&#xff0c;一个看似流畅的回答背后&#xff0c;可能隐藏着致命的风险——模型“自信地胡说八道”。这种现象在金融咨询、医疗建议或法律条款解释中尤为危险。用户真正需要的不是最流…

作者头像 李华
网站建设 2026/8/16 13:59:17

Kotaemon跨界联名创意:品牌合作点子库

Kotaemon跨界联名创意&#xff1a;品牌合作点子库 在智能客服逐渐从“能说话”迈向“懂业务”的今天&#xff0c;越来越多企业发现&#xff0c;一个真正可用的AI助手&#xff0c;远不止是调用大模型生成几句回复那么简单。它需要理解上下文、引用真实知识、执行具体任务&#x…

作者头像 李华