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

【数据结构回顾】

数据结构回顾

  • 一、单链表
  • 二、单循环链表

一、单链表

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>typedef struct Node {int data;Node *next;
}Node;Node* initList()
{Node *list = (Node*)malloc(sizeof(Node));list->data = 0;list->next = NULL;return list;
}void headInsert(Node* L, int data)
{Node *node = (Node*)malloc(sizeof(Node));node->data = data;node->next = L->next;L->next = node;L->data++;
}void tailInsert(Node* L, int data)
{Node *List = L;Node *node = (Node*)malloc(sizeof(Node));node->data = data;while (List->next){List = List->next;}node->next = List->next;List->next = node;L->data++;
}int delete_node(Node* L, int data)
{Node *pre = L;Node *current = L->next;while(current){if (current->data==data){pre->next = current->next;free(current);L->data--;return true;}else{pre = current;current = current->next;}}return false;
}void printList(Node* L)
{while (L->next){L = L->next;printf("node = %d\n", L->data);}
}int main()
{Node* L = initList();headInsert(L, 1);headInsert(L, 2);headInsert(L, 3);headInsert(L, 4);headInsert(L, 5);tailInsert(L, 6);tailInsert(L, 7);printList(L);if (delete_node(L, 3)) {printf("success delete\n");}else {printf("fail delete\n");}printList(L);system("pause");return 0;
}

二、单循环链表

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>typedef struct Node {int data;Node *next;
}Node;Node* initList() 
{Node *L = (Node*)malloc(sizeof(Node));L->next = NULL;L->data = 0;L->next = L;return L;
}void headInsert(Node* L, int data)
{Node *node = (Node*)malloc(sizeof(Node));node->data = data;node->next = L->next;L->next = node;L->data++;
}void tailInsert(Node* L, int data)
{Node *List = L;Node *node = (Node*)malloc(sizeof(Node));while (List->next!=L){List = List->next;}node->data = data;node->next = L;List->next = node;L->data++;
}int delete_node(Node* L, int data)
{Node *pre = L;Node *current = L->next;while (current!=L){if (current->data == data){pre->next=current->next;free(current);L->data--;return true;}else{pre = current;current = current->next;}	}return false;
}void printList(Node* L)
{Node *node = L->next;while (node !=L){printf("%d->", node->data);node=node->next;}printf("NULL\n");
}
int main()
{Node* L = initList();headInsert(L, 1);headInsert(L, 2);headInsert(L, 3);headInsert(L, 4);headInsert(L, 5);tailInsert(L, 6);tailInsert(L, 7);printList(L);delete_node(L, 4);delete_node(L, 7);printList(L);system("pause");return 0;
}
http://www.lryc.cn/news/150159.html

相关文章:

  • QT创建可移动点类
  • Flutter启动页
  • 读word模板批量生成制式文件
  • Node.js crypto模块 加密算法
  • Win11 避坑安装WSL2 Ubuntu22.04
  • ESP8266+继电器+MQTT+VUE 实现远程开关灯
  • Android中级——四大组件工作过程
  • 【RabbitMQ】RabbitMQ 服务无法启动。系统出错。发生系统错误 1067。进程意外终止。
  • 如何理解attention中的Q、K、V?
  • Redis----取代RabbitMq 和 Kafka的解决方案
  • 动态规划之连续乘积最大子数组 连续和最大子数组
  • keil在点击debug无法运行(全速运行)
  • go语言-协程
  • 如何伪造http头,让后端认为是本地访问
  • 视频剪辑音效处理软件有哪些?视频剪辑软件那个好用
  • 搭建STM32F407的Freertos系统(基于STM32CubeMX)
  • vite 配置自动补全文件的后缀名
  • 基于Spring Boot的人才公寓管理系统设计与实现(Java+spring boot+MySQL)
  • Python 编写函数
  • C# Solidworks二次开发:创建距离配合以及移动组件API详解
  • Excel:通过Lookup函数提取指定文本关键词
  • sql:SQL优化知识点记录(六)
  • C#搭建WebSocket服务实现通讯
  • eclipse/STS(Spring Tool Suite)安装CDT环境(C/C++)
  • Python爬虫抓取经过JS加密的API数据的实现步骤
  • Nacos基础(2)——nacos的服务器和命名空间 springBoot整合nacos 多个nacos配置的情况
  • Win7设备和打印机里空白,0个对象,但是可以打印的处理办法
  • Python基础学习第六天:Python 数据类型
  • C++信息学奥赛1184:明明的随机数
  • NoSQL技术——Redis