【數據結構】鏈式隊列

鏈式隊列實現:

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.pswp.cn/news/697065.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/697065.shtml
英文地址,請注明出處:http://en.pswp.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年海上風電項目加速…