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

7.9数据结构

思维导图

作业

doubleloop.h

#ifndef __DOUBLELOOP_H__
#define __DOUBLELOOP_H__#include <stdio.h>
#include <stdlib.h>typedef int datatype;
typedef struct node
{union{int len;datatype data;};struct node *pri;//前驱指针struct node *next;//后继指针
}node,*node_p;//创建链表
node_p list_create();
//创建节点
node_p node_create(node_p H,datatype data);
//判空
int node_empty(node_p H);
//尾插
int tail_input(node_p H,datatype data);
//遍历
int node_show(node_p H);
//尾删
int del_tail(node_p H);
//销毁
int node_free(node_p H);#endif

doubleloop.c

#include "doubleloop.h"//创建链表
node_p list_create()
{node_p H=(node_p)malloc(sizeof(node));if(NULL==H){printf("---创建链表失败---\n");return NULL;}H->len=0;H->pri=H;H->next=H;printf("---创建链表成功---\n");return H;
}
//创建节点
node_p node_create(node_p H,datatype data)
{node_p new=(node_p)malloc(sizeof(node));if(new==NULL){printf("---创建节点失败---\n");return 	NULL;}new->data=data;new->pri=H;new->next=H;return new;
}
//判空
int node_empty(node_p H)
{if(H==NULL){printf("---入参为空,请检查---\n");return -1;}return H->next==H;
}//尾插
int tail_input(node_p H,datatype data)
{if(H==NULL){printf("---入参为空,请检查---\n");return 0;}node_p new=node_create(H,data);node_p p=H->next;while(p->next!=H){p=p->next;}new->pri=p;p->next=new;H->len++;return 1;
}
//遍历
int node_show(node_p H)
{if(H==NULL||node_empty(H)){printf("---输出有误---\n");return 0;}node_p p=H->next;printf("链表为:H->");while(p!=H){printf("%d->",p->data);p=p->next;}printf("H\n");return 1;
}//尾删
int del_tail(node_p H)
{if(H==NULL||node_empty(H)){printf("---尾删失败,请检查---\n");return 0;}node_p p=H;//H会找到需要位置的前一个节点for(int i=0;i<H->len-1;i++)//len和pos是一个意思,是位置而不是下标,-1为了移动到最后一个的前一个节点停止{p=p->next;}node_p q=p->next;//定义出最后一个节点,方便释放空间p->next=H;//将倒数第二个节点指向NULL,一根线free(q);q=NULL;H->len--;return 1;
}//销毁
int node_free(node_p H)
{if(H==NULL){printf("---链表销毁有误,请检查---\n");return 0;}while(H->next!=H){del_tail(H);}free(H);H=NULL;printf("---链表销毁成功---\n");return 1;
}

http://www.lryc.cn/news/396181.html

相关文章:

  • Python 文件操作:打开数据处理的大门
  • 单对以太网连接器多场景应用
  • Python pip的更新问题
  • [Linux][Shell][Shell基础] -- [Shebang][特殊符号][变量][父子Shell]详细讲解
  • DS200CVMAG1AEB处理器 控制器 模块
  • 阈值分割后配合Connection算子和箭头工具快速知道区域的ID并选择指定区域
  • 【work】AI八股-神经网络相关
  • 【LeetCode】12. 小张刷题计划
  • Tomcat部署以及优化
  • ubuntu 22 安装 lua 环境 编译lua cjson 模块
  • 地下城游戏中都有哪些类型的服务器?
  • 大模型面试(二)
  • rsync远程同步--累了,明天继续再写~。
  • 每日刷题(二分查找,匈牙利算法,逆序对)
  • LLM应用构建前的非结构化数据处理(三)文档表格的提取
  • 如何从数码相机恢复已删除的照片
  • 设计模式使用场景实现示例及优缺点(创建型模式——单例模式、建造者模式、原型模式)
  • LAMP万字详解(概念、构建步骤)
  • 金南瓜科技SECS/GEM:引领智能制造新潮流
  • 昇思训练营打卡第二十一天(DCGAN生成漫画头像)
  • 东方通Tongweb发布vue前端
  • spring xml实现bean对象(仅供自己参考)
  • MiniGPT-Med 通用医学视觉大模型:生成医学报告 + 视觉问答 + 医学疾病识别
  • 如何判断ip地址在同一个网段:技术解析与实际应用
  • linux高级编程(TCP)(传输控制协议)
  • 【常见开源库的二次开发】一文学懂CJSON
  • 点云下采样有损压缩
  • AutoHotKey自动热键(六)转义符号
  • 第16章 主成分分析:四个案例及课后习题
  • 股票分析系统设计方案大纲与细节