news 2026/6/23 21:31:35

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/6/23 14:32:37

蜣螂优化(DBO)算法在工程实际中求目标函数最小值的例子:压力容器设计成本最小化的4变量4约束...

蜣螂优化(DBO)算法 工程实际&#xff0c;求目标函数最小值&#xff0c;图中所求例子为一个压力容器设计成本最小&#xff0c;为4变量&#xff0c;4个不等式约束。 采用罚函数将4约束问题转变为无约束问题。 代码注释完整&#xff0c;非常容易带入自己想要求的问题。深夜撸代码发…

作者头像 李华
网站建设 2026/6/23 19:36:32

12、游戏内存中常见数据结构解析

游戏内存中常见数据结构解析 在游戏开发和内存分析中,了解常见的数据结构及其在内存中的存储方式是非常重要的。下面将详细介绍几种常见的数据结构,包括 std::vector 、 std::list 和 std::map ,并说明如何判断游戏数据是否存储在这些结构中。 1. 字符串相关类 在处…

作者头像 李华
网站建设 2026/6/23 19:18:47

21、游戏响应式黑客技术全解析

游戏响应式黑客技术全解析 在游戏世界里,玩家们总是追求更快的反应速度和更多的游戏信息。而响应式黑客技术,就为玩家提供了一种超越人类反应极限的可能。 1. 游戏基础机制与ESP黑客技术 游戏中,常常会根据玩家的位置每帧重新计算当前楼层值,为了防止该值在每次重绘帧时…

作者头像 李华
网站建设 2026/6/23 20:40:08

26、游戏隐藏与反检测技术全解析

游戏隐藏与反检测技术全解析 在游戏开发与游玩过程中,为了避免游戏程序被调试、检测,开发者和玩家常常需要运用各种技术手段隐藏程序的行为和特征。下面将详细介绍一些常见的反调试、反检测技术及其实现方法。 反调试技术 当检测到调试器时,可以采用多种方法混淆控制流,…

作者头像 李华
网站建设 2026/6/22 15:55:11

Kotaemon网络安全问答:CVE漏洞快速查询

Kotaemon网络安全问答&#xff1a;CVE漏洞快速查询 在现代企业安全运营中&#xff0c;面对每天新增数十个的公开漏洞&#xff08;CVE&#xff09;&#xff0c;安全团队正面临前所未有的信息过载压力。一个典型的场景是&#xff1a;某位安全分析师刚收到一封关于“Windows提权漏…

作者头像 李华
网站建设 2026/6/23 19:53:41

Kotaemon能否自动识别问题紧急程度?

Kotaemon能否自动识别问题紧急程度&#xff1f; 在企业智能化转型的浪潮中&#xff0c;客服系统早已不再满足于“有问必答”的基础功能。越来越多的组织发现&#xff0c;面对成千上万的用户请求&#xff0c;如果不能快速区分哪些是需要立即响应的“火警级”问题&#xff0c;哪些…

作者头像 李华