【数据结构】链式队列

链式队列实现:

1.创建一个空队列

2.尾插法入队

3.头删法出队

4.遍历队列

一、main函数

 #include <stdio.h>                                                #include "./3.linkqueue.h"                                        int main(int argc, const char *argv[])                            {                                                                 linkpos* pos = create_linkqueue();                            show_linkqueue(pos);insertENd_linkqueue(pos,111);                                 insertENd_linkqueue(pos,222);                                 insertENd_linkqueue(pos,333);                                 insertENd_linkqueue(pos,444);                                 insertENd_linkqueue(pos,555);                                 show_linkqueue(pos);                                          dataType num = output_linkqueue(pos);                         printf("出队的数据为:%d\n",num);                             show_linkqueue(pos);                                          return 0;                                                     }                                                                 

二、功能函数

#include <stdio.h>                                                    
#include <stdlib.h>                                                   
#include "./3.linkqueue.h"                                            //创建                                                                
linkpos* create_linkqueue()                                           
{                                                                     linkpos* pos = (linkpos*)malloc(sizeof(linkpos));                 pos->front = (linkqueue*)malloc(sizeof(linkqueue));               if(NULL == pos->front)                                            {                                                                 printf("队列创建失败\n");                                     return NULL;                                                  }                                                                 pos->front->next =NULL;                                           pos->rear = pos->front;                                           pos->front->text.len = 0;                                         return pos;                                                       
}                                                                     //判空                                                                
int isEmpty_linkqueue(linkpos*pos)                                    
{                                                                     return pos->front == pos->rear?1:0;                               
}                                                                     //遍历                                                                
void show_linkqueue(linkpos*pos)                                      
{                                                                     if(isEmpty_linkqueue(pos))                                        {                                                                 printf("队列为空!\n");                                       return ;                                                      }                                                                 linkqueue* p = pos->front->next;                                  while(p != pos->rear)                                             {                                                                 printf("%d ",p->text.data);                                   p=p->next;                                                    }                                                                 printf("\n");                                                     return ;                                                          
}                                                                     //尾插 入队                                                           
void insertENd_linkqueue(linkpos*pos,dataType num)                    
{                                                                     linkqueue* temp = (linkqueue*)malloc(sizeof(linkqueue));          if(NULL == temp)                                                  {                                                                 printf("结点创建失败,入队失败\n");                           return;                                                       }                                                                 temp->next = NULL;                                                temp->text.data = num;                                            temp->next = pos->rear->next;                                     pos->rear->next = temp;                                           pos->rear = pos->rear->next;                                      pos->front->text.len++;                                           return;                                                           }                                                                     //头删 出队                                        
dataType output_linkqueue(linkpos*pos)             
{                                                  if(isEmpty_linkqueue(pos))                     {                                              printf("队列为空,无法出队\n");            return (dataType)-1;                       }                                              linkqueue* temp;                               temp = pos->front->next;                       pos->front->next = temp->next;                 dataType num =temp->text.data; if(pos->front->next == NULL) {pos->rear = pos->front;}               free(temp);                                    return num;                                    
}                                                  

三、头文件

 #ifndef __LINKQUEUE_H__#define __LINKQUEUE_H__typedef int dataType;union msg{dataType data;int len;};typedef struct node{union msg text;struct node* next;}linkqueue;typedef struct{linkqueue* front;linkqueue* rear;}linkpos;linkpos* create_linkqueue();void insertENd_linkqueue(linkpos*pos,dataType num);dataType output_linkqueue(linkpos*pos);void show_linkqueue(linkpos*pos);                           #endif

四、运行结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/697065.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

文档控件DevExpress Office File API v23.2新版亮点 - 支持SVG

DevExpress Office File API是一个专为C#, VB.NET 和 ASP.NET等开发人员提供的非可视化.NET库。有了这个库&#xff0c;不用安装Microsoft Office&#xff0c;就可以完全自动处理Excel、Word等文档。开发人员使用一个非常易于操作的API就可以生成XLS, XLSx, DOC, DOCx, RTF, CS…

数据结构之单链表的操作

main函数 #include <stdio.h> #include "./03_linkList.h" int main(int argc, const char *argv[]) { linkList* head creatr_linkList(); insertHead_linkL…

运维SRE-19 网站Web中间件服务-http-nginx

Ans自动化流程 1.网站集群核心协议&#xff1a;HTTP 1.1概述 web服务&#xff1a;网站服务&#xff0c;网站协议即可. 协议&#xff1a;http协议,https协议 服务&#xff1a;Nginx服务&#xff0c;Tengine服务....1.2 HTTP协议 http超文本传输协议&#xff0c;负责数据在网站…

更高效的构建工具-vite

更高效的构建工具-vite 前言Vite是什么Vite和webpack的比较1. 运行原理2. 使用成本 Vite的初体验 前言 首先我们要认识什么时构建工具&#xff1f; 企业级项目都具备什么功能呢&#xff1f; Typescript&#xff1a;如果遇到ts文件&#xff0c;我们需要使用tsc将typescript代码…

Android约束布局中用ConstraintHelper实现过渡动画效果

前些天发现了一个蛮有意思的人工智能学习网站,8个字形容一下"通俗易懂&#xff0c;风趣幽默"&#xff0c;感觉非常有意思,忍不住分享一下给大家。 &#x1f449;点击跳转到教程 一.创建一个类CircularRevealHelper继承ConstraintHelper代码如下 /*** Author: ly* Da…

【Linux从青铜到王者】 基础IO

本篇重点&#xff1a;文件描述符&#xff0c;重定向&#xff0c;缓冲区&#xff0c;磁盘结构&#xff0c;文件系统&#xff0c;inode理解文件的增删查改&#xff0c;查找一个文件为什么一定要有路径&#xff0c;动静态库&#xff0c;有的时候为什么找不到库&#xff0c;动态库的…

JavaWeb——003Axios Vue组件库(Element)

目录 一、Ajax 1、同步与异步​编辑 2、原生Ajax&#xff08;繁琐&#xff09;​编辑 2.1、写一个简易的Ajax 3、Axios&#xff08;推荐使用&#xff09;​编辑 3.1、Axios入门 3.2、Axios请求方式别名 3.3、案例&#xff1a;基于Vue及Axios完成数据的动态加载展示​编…

Flink CDC 3.0 表结构变更时导致webUI接口无反应原因

Flink CDC 3.0 表结构变更时导致webUI接口无反应&#xff01; 原因&#xff1a;因为deliverCoordinationRequestToCoordinator和requestJob都是SchedulerNG中方法&#xff0c;该类的线程模型是单线程执行&#xff0c;所以在deliverCoordinationRequestToCoordinator执行表结构…

mysql创建数据库,用户授权

一、创建用户 CREATE USER 用户名% IDENTIFIED BY 密码; flush privileges; 二、更新用户密码 update mysql.user set authentication_stringpassword("密码") where userroot; flush privileges; 三、允许root远程登录 update user set host % where user r…

AIoT网关 人工智能物联网网关

AIoT(人工智能物联网)作为新一代技术的代表&#xff0c;正以前所未有的速度改变着我们的生活方式。在这个智能时代&#xff0c;AIoT网关的重要性日益凸显。它不仅是连接智能设备和应用的关键&#xff0c;同时也是实现智能化家居、智慧城市和工业自动化的必备技术。      一…

c# entity freamwork 判断是否存在

在 Entity Framework (EF) 中&#xff0c;你可以使用 LINQ 查询来判断数据库中是否存在特定条件的记录。以下是一些常见的方法&#xff1a; 使用 Any 方法: using (var context new YourDbContext()) {bool exists context.YourEntity.Any(e > e.Property yourValue);i…

【linux进程间通信(二)】共享内存详解以及进程互斥概念

&#x1f493;博主CSDN主页:杭电码农-NEO&#x1f493;   ⏩专栏分类:Linux从入门到精通⏪   &#x1f69a;代码仓库:NEO的学习日记&#x1f69a;   &#x1f339;关注我&#x1faf5;带你学更多操作系统知识   &#x1f51d;&#x1f51d; 进程间通信 1. 前言2. 共享内…

2024年2月23日 晨会汇报

Good morning, colleages! This is /ˈdɑː.tʃi/ speaking. As for my report today, I decide to wing it, so I didnt prepare a script. Now, Ill share an update about my recent work activities which encompasses two key area: a summary of my work yesterday a…

【Go channel如何控制goroutine并发执行顺序?】

多个goroutine并发执行时&#xff0c;每一个goroutine抢到处理器的时间点不一致&#xff0c;gorouine的执行本身不能保证顺序。即代码中先写的gorouine并不能保证先执行 思路&#xff1a;使用channel进行通信通知&#xff0c;用channel去传递信息&#xff0c;从而控制并发执行…

基于开源模型对文本和音频进行情感分析

应用场景 从商品详情页爬取商品评论&#xff0c;对其做舆情分析&#xff1b;电话客服&#xff0c;对音频进行分析&#xff0c;做舆情分析&#xff1b; 通过开发相应的服务接口&#xff0c;进一步工程化&#xff1b; 模型选用 文本&#xff0c;选用了通义实验室fine-tune的st…

电脑录屏软件哪个好用?实测告诉你答案(2024年最新)

在当今信息化快速发展的时代&#xff0c;无论是录制在线课程、游戏操作&#xff0c;还是制作教程、会议记录&#xff0c;一款电脑录屏软件显得尤为重要&#xff0c;可是电脑录屏软件哪个好用呢&#xff1f;本文将介绍三款主流的电脑录屏软件&#xff0c;通过分步骤详细讲述&…

使用maven集成spring在测试的时候报出了如下的异常:version 60

使用maven集成spring在测试的时候报出了如下的异常&#xff1a; Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 60 解决&#xff1a;

在word中将latex格式的公式转化为带有编号的mathtype公式

在word中将latex格式的公式转化为带有编号的mathtype公式 1.先在word里面配置好mathtype2.在word中设置mathtype的格式3.先将latex格式的公式转化为mathml格式4.读到这里&#xff0c;是不是觉得这个方法麻烦 1.先在word里面配置好mathtype 注意&#xff1a;1.word的版本应该是 …

基于springboot+vue的中小型医院网站(前后端分离)

博主主页&#xff1a;猫头鹰源码 博主简介&#xff1a;Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战&#xff0c;欢迎高校老师\讲师\同行交流合作 ​主要内容&#xff1a;毕业设计(Javaweb项目|小程序|Pyt…

Sovit3D数字孪生平台 助力智慧海上风电场项目加速

我们常说地球是蓝色星球&#xff0c;那是因为海洋约占地球面积的71%。如今&#xff0c;我国正在向“双碳”目标不断奋斗&#xff0c;海上风电也作为一种潜力清洁能源&#xff0c;迸发出前所未有的活力&#xff0c;海上吹来的风成为未来清洁能源新方向。 2024年海上风电项目加速…