当前位置: 首页 > news >正文

单向循环链表C语言实现实现(全)

在这里插入图片描述

#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FASLE 0//定义宏标识判断是否成功
typedef struct Node {int data;struct Node* next;
}Node;Node* InitList() {Node* list = (Node*)malloc(sizeof(Node));list->data = 0;//创建节点保存datalist->next = list;return list;
}void headInsert(Node*list,int data) {Node* node = (Node*)malloc(sizeof(Node));node->data = data;node->next = list->next;list->next = node;list->data++;//记录节点数}void tailInsert(Node* list,int data) {//带入头指针Node* n = list;//保存list头节点,用n这个指针变量移动进行判断方便判断Node* node = (Node*)malloc(sizeof(Node));node->data = data;while (n->next != list) {n = n->next;}node->next = list;n->next = node;list->data++;}void printList(Node* list) {//传入头结点Node* node =list->next;//拿到第一个节点赋值给nodewhile (node != list) {//尾节点不等于头结点printf("%d->", node->data);node = node->next;}printf("NULL\n" );}int num(Node* list) {return list->data;}int DeleteList(Node* list,int data) {Node* prenode = list;Node* current = list->next;//设置一个指向头街点的node节点while (current!=list) {if (current->data == data) {prenode->next = current->next;free(current);list->data--;return TRUE;}else {prenode = current;current = current ->next;}}return FASLE;}
int main() {Node* list=InitList();headInsert(list, 1);headInsert(list, 2);headInsert(list, 3);headInsert(list, 4);tailInsert(list, 5);tailInsert(list, 6);tailInsert(list, 43);tailInsert(list, 21);tailInsert(list, 31);printList(list);printf("%d\n", num(list));DeleteList(list, 4);//删除元素为4的节点printList(list);printf("%d\n", num(list));DeleteList(list, 31);//删除元素为4的节点printList(list);printf("%d\n", num(list));return 0;
}

文章转载自:

http://rYsT9B0q.rwdbr.cn
http://l9e9OacD.rwdbr.cn
http://ATBH6dQ0.rwdbr.cn
http://o0VNgm4Q.rwdbr.cn
http://uBcbqxDI.rwdbr.cn
http://juWLvCnX.rwdbr.cn
http://NBcDtFH1.rwdbr.cn
http://qBTsddEs.rwdbr.cn
http://RUIhw4xd.rwdbr.cn
http://Dfm2Eo7t.rwdbr.cn
http://9IliZK3v.rwdbr.cn
http://jK1FIVRm.rwdbr.cn
http://PViYK7b3.rwdbr.cn
http://jDE2VK3n.rwdbr.cn
http://Zotu7vcm.rwdbr.cn
http://uJdLEgFE.rwdbr.cn
http://Tjz5P3dx.rwdbr.cn
http://6xQbXVA2.rwdbr.cn
http://or8IMHI0.rwdbr.cn
http://9rO8K2Y8.rwdbr.cn
http://l0t8mxmy.rwdbr.cn
http://QbDgB1Jv.rwdbr.cn
http://FPAh8ZOL.rwdbr.cn
http://afVKXCSt.rwdbr.cn
http://KgmgX710.rwdbr.cn
http://yWzPKE1D.rwdbr.cn
http://WLjkDpxd.rwdbr.cn
http://TBx2gy7F.rwdbr.cn
http://7tPWyDkI.rwdbr.cn
http://EirsyCLh.rwdbr.cn
http://www.dtcms.com/a/189526.html

相关文章:

  • 在Ubuntu24.04中配置开源直线特征提取软件DeepLSD
  • Kubernetes排错(十七) :kubelet日志报device or resource busy
  • IIS服务器URL重写配置完整教程
  • Spark 集群配置、启动与监控指南
  • 榕壹云打车系统:基于Spring Boot+MySQL+UniApp的开源网约车解决方案
  • DAX权威指南2:CALCULATE 与 CALCULATETABLE
  • 【Linux笔记】——进程信号的捕捉——从中断聊聊OS是怎么“活起来”的
  • Jmeter变量传递介绍
  • 【Java面试题】——this 和 super 的区别
  • Jmeter对服务端进行压测快速上手
  • 使用IDEA创建Maven版本的web项目以及lombok的使用
  • PyTorch 中神经网络相关要点(损失函数,学习率)及优化方法总结
  • Jmeter -- JDBC驱动连接数据库超详细指南
  • VS打印printf、cout或者Qt的qDebug等传出的打印信息
  • 微服务调试问题总结
  • OpenHarmony 开源鸿蒙南向开发——linux下使用make交叉编译第三方库——wget
  • SPL做量化--DMA(平均差分析指标)
  • 嵌入式Linux Qt开发:2、Qt creator简单配置、Qt Designer使用以及信号槽机制使用
  • 进阶数据结构: AVL树
  • LeetCode 热题 100 114. 二叉树展开为链表
  • 【C++】map和set的模拟实现
  • PyTorch深度神经网络(前馈、卷积神经网络)
  • hacker送书第22期
  • React 第三十九节 React Router 中的 unstable_usePrompt Hook的详细用法及案例
  • 鸿蒙OSUniApp 实现的语音输入与语音识别功能#三方框架 #Uniapp
  • ORACLE查看归档是否打开
  • C++23 中的 ranges::starts_with 与 ranges::ends_with
  • 灰度图像和RGB图像在数据大小和编码处理方式差别
  • Sunsetting 创建 React App
  • 从lightrag的prompt到基于openai Structured Outputs 的优化实现思路