C语言 实现 链 显示 效果 查找 修改 删除

news/2024/10/23 9:32:24/

显示所有信息
2023年10月1日的描述:今天放假
2023年10月2日的描述:今天有体育
2023年10月3日的描述:今天有数学
2023年10月4日的描述:今天有语文
2023年10月5日的描述:今天有政治
2023年10月6日的描述:今天交学费
2023年10月7日的描述:今天周末
2023年10月8日的描述:今天给家里打电话
2023年10月9日的描述:今天给同学辅导数学
2023年10月10日的描述:今天上体育


查找 2023,10,4号的信息
2023年10月4日的描述:今天有语文


更改2023年10月4的信息
[更改]请输入2023年10月4日的描述:中华人民共和国
修改后的节点信息是:
2023年10月4日的描述:中华人民共和国


删除2023年10月5号的记录
2023年10月5日的描述:今天有政治
以上节点信息从链上被剔除~!


显示所有信息
2023年10月1日的描述:今天放假
2023年10月2日的描述:今天有体育
2023年10月3日的描述:今天有数学
2023年10月4日的描述:中华人民共和国
2023年10月6日的描述:今天交学费
2023年10月7日的描述:今天周末
2023年10月8日的描述:今天给家里打电话
2023年10月9日的描述:今天给同学辅导数学
2023年10月10日的描述:今天上体育
所有节点释放完毕~!

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<string.h>typedef struct Date {int year, month, day;
}Date_t;typedef struct Node {Date_t date;//日期char describe[200];//描述struct Node* next;
}Node_t,*ListLink;void init(ListLink* L) {*L = malloc(sizeof(Node_t));    if (!L) //如果分配失败exit(1);(*L)->next = NULL;
}void push_back(ListLink* L,Node_t node) {static ListLink tail;if ((*L)->next == NULL) {tail = *L;}Node_t* newNode = malloc(sizeof(Node_t));if (!newNode) //如果分配失败exit(1);newNode->date = node.date;strcpy(newNode->describe, node.describe);newNode->next = NULL;tail->next = newNode;tail = newNode;
}Node_t creatNode(int year,int month,int day,char * describe) {    Node_t node;node.date.year = year;node.date.month = month;node.date.day = day;node.next = NULL;strcpy(node.describe, describe);return node;
}int cmp(Date_t a, Date_t b) { //分析两个日期是否一直,一直返回1if (a.year != b.year)return 0;if (a.month != b.month)return 0;if (a.day != b.day)return 0;return 1;
}Node_t* findByDate(ListLink L,Date_t date) {//根据年月日查找节点是否存在ListLink p = L->next;while (p) {if (cmp(p->date, date))//如果找到了对应日期,返回return p;p = p->next;}return p;//没找到返回的必是空
}void showNode(Node_t* node) {//显示一个节点的信息    printf("%d年%d月%d日的描述:", node->date.year, node->date.month, node->date.day);puts(node->describe);
}void edit(Node_t*node) {printf("[更改]请输入%d年%d月%d日的描述:",node->date.year, node->date.month, node->date.day);gets(node->describe);puts("修改后的节点信息是:");showNode(node);
}void delete(ListLink *L,Date_t date) {//找到指定节点的前一个节点ListLink previous = (*L);ListLink current = (*L)->next;while (current) {if (cmp(current->date, date))//如果找到了对应日期,返回break;previous = current;current = current->next;}if (current) {previous->next = current->next;showNode((Node_t*)current);puts("以上节点信息从链上被剔除~!");free(current);}else {puts("删除失败,没有此日期的节点");}     
}void printAll(ListLink L) {    ListLink current = L->next;while (current) {showNode(current);current = current->next;}
}void destruction(ListLink* L) {//销毁整个链Node_t* current;if (*L == NULL)return;current = (*L)->next;while (current) {     (*L)->next = current->next;free(current);current = (*L)->next;      }free(*L);puts("所有节点释放完毕~!");
}int main()
{ListLink L;Node_t* node;Date_t date;init(&L);push_back(&L, creatNode(2023, 10, 1, "今天放假"));push_back(&L, creatNode(2023, 10, 2, "今天有体育"));push_back(&L, creatNode(2023, 10, 3, "今天有数学"));push_back(&L, creatNode(2023, 10, 4, "今天有语文"));push_back(&L, creatNode(2023, 10, 5, "今天有政治"));push_back(&L, creatNode(2023, 10, 6, "今天交学费"));push_back(&L, creatNode(2023, 10, 7, "今天周末"));push_back(&L, creatNode(2023, 10, 8, "今天给家里打电话"));push_back(&L, creatNode(2023, 10, 9, "今天给同学辅导数学"));push_back(&L, creatNode(2023, 10, 10, "今天上体育"));//显示所有信息puts("\n\n显示所有信息");printAll(L);//查找 2023,10,4号的信息puts("\n\n查找 2023,10,4号的信息");date.year = 2023;date.month = 10;date.day = 4;node = findByDate(L,date);showNode(node);//更改10月4的信息puts("\n\n更改2023年10月4的信息");edit(node);//删除2023年10月5号的记录puts("\n\n删除2023年10月5号的记录");date.year = 2023;date.month = 10;date.day = 5;delete(&L,date);//显示所有信息puts("\n\n显示所有信息");printAll(L);destruction(&L);return 0;
}


http://www.ppmy.cn/news/1138552.html

相关文章

利用freesurfer6进行海马分割的环境配置和步骤,以及获取海马体积

利用freesurfer6进行海马分割的环境配置和步骤 Matlab Runtime 安装1. 运行recon-all&#xff1a;2. 利用 recon-all -s subj -hippocampal-subfields-T1 进行海马分割3. 结束后需要在/$SUBJECTS_DIR/subject/的文件夹/mri路径下输入下面的代码查看分割情况4. 在文件SUBJECTS_D…

C++基础语法——unordered_map和unordered_set

目录 1. unordered系列关联式容器 2.unordered_map ①unordered_map的简介 ②unordered_map的构造 ③unordered_map的容量 ④unordered_map的迭代器 ⑤unordered_map的元素访问 ⑥unordered_map的查询 ⑦unordered_map的修改 ⑧unordered_map的桶操作 3.使用与对比测…

tkinter中如何执行,单击按钮后的线程操作

在Tkinter中&#xff0c;按钮可以绑定一个回调函数来处理点击事件。如果你想在按钮点击时执行一个线程操作&#xff0c;可以在回调函数中创建一个新的线程来处理这个操作。 #我的Python教程 #官方微信公众号&#xff1a;wdPython以下是一个简单的示例代码&#xff0c;演示如何…

条件查询和数据查询

一、后端 1.controller层 package com.like.controller;import com.like.common.CommonDto; import com.like.entity.User; import com.like.service.UserService; import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import …

【C语言】模拟实现strstr

strstr这个库函数看到这个名字大概率猜不到这是什么函数&#xff0c; 但经过学习就可以很好的认识到这个函数 目录 介绍&#xff1a;模拟实现&#xff1a;思路&#xff1a;代码实现&#xff1a; 介绍&#xff1a; 可以看到此函数是用来寻找一个字符串中是否含有另一个字符串 代…

视频号规则改动,不再支持拍单,传统无货源模式已行不通!

视频号小店批量铺货行不通了&#xff0c;大家好我是派大星&#xff0c;这两天视频号发布了一个公告&#xff0c; 核心信息呢就是10月7号&#xff0c;视频号小店&#xff0c;将无法直接查看消费者的详细下单信息&#xff0c;只能通过电子面单的形式&#xff0c;打单发货。每个店…

CTFHUB - SSRF

目录 SSRF漏洞 攻击对象 攻击形式 产生漏洞的函数 file_get_contents() fsockopen() curl_exec() 提高危害 利用的伪协议 file dict gopher 内网访问 伪协议读取文件 端口扫描 POST请求 总结 上传文件 总结 FastCGI协议 CGI和FastCGI的区别 FastCGI协议 …

《protobuf》基础语法3

文章目录 默认值更新规则保留字段未知字段 默认值 在反序列化时&#xff0c;若被反序列化的二进制序列中不包含某个字段&#xff0c;则在反序列化时&#xff0c;就会设置对应默认值。不同的类型默认值不同&#xff1a; 类型默认值字符串“”布尔型false数值类型0枚举型0设置了…