中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

學做網(wǎng)站論壇vip賬戶如何注冊百度賬號

學做網(wǎng)站論壇vip賬戶,如何注冊百度賬號,咸寧市政府門戶網(wǎng)站集約建設項目,小程序代理平臺1.隊列的概念以及結(jié)構(gòu) 隊列:只允許在一端進行插入數(shù)據(jù)操作,在另一端進行刪除數(shù)據(jù)操作的特殊線性表,隊列具有先進先出FIFo(Frist in Frist out)的特性 入隊列:進行插入才操作的一端稱為隊尾 出隊列:進行刪除操作的一…

1.隊列的概念以及結(jié)構(gòu)

隊列:只允許在一端進行插入數(shù)據(jù)操作,在另一端進行刪除數(shù)據(jù)操作的特殊線性表,隊列具有先進先出FIFo(Frist in Frist out)的特性

隊列:進行插入才操作的一端稱為隊尾

隊列:進行刪除操作的一端稱為隊頭

2.隊列的實現(xiàn)

隊列也可以使用數(shù)組和鏈表的結(jié)構(gòu)實現(xiàn),使用鏈表的結(jié)構(gòu)實現(xiàn)更優(yōu)一些,因為如果使用數(shù)組的結(jié)構(gòu),出隊列在數(shù)組頭上出數(shù)據(jù),效率會很低

隊列常見的基本操作:

//初始化
void QueueInit(Queue* pq);
//清空隊列成員
void QueueDestroy(Queue* pq);
//隊尾插入元素
void QueuePush(Queue* pq, QDataType x);
//刪除隊隊頭元素,隊列先進先出
void QueuePop(Queue* pq);
//獲取隊頭元素
int QueueFront(Queue * pq);
//獲取隊尾元素
int QueueBack(Queue* pq);
//獲取隊列中有效與元素個數(shù)
int QueueSize(Queue* pq);
//查看隊列是否為空
bool QueueEmpty(Queue* pq);

每個功能的實現(xiàn)以及解釋

實現(xiàn)隊列這里我們使用的是動態(tài)順序表

->1.初始化隊列

//初始化
void QueueInit(Queue* pq)
{assert(pq);pq->head = pq->tail = NULL;pq->size = 0;
}

->2.清空隊列成員

//清空隊列成員
void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->head;//QNode* cur = pq->head->next;while (cur){/*free(pq->head);pq->head = cur;cur = cur->next;*/QNode* next = cur->next;free(cur);cur = next;}pq->head = pq->tail = NULL;pq->size = 0;
}

->3.隊尾插入元素

//隊尾插入元素
void QueuePush(Queue* pq, QDataType x)
{QNode* newnode = (QNode*)malloc(sizeof(QNode));if (NULL == newnode){perror("QueuePsuh::malloc");return;}newnode->data = x;newnode->next = NULL;if (pq->head == NULL){assert(pq->tail == NULL);pq->head = pq->tail = newnode;}else{pq->tail->next = newnode;pq->tail = newnode;}pq->size++;
}

->4.刪除隊隊頭元素,隊列先進先出

//刪除隊列成員,隊列先進先出
void QueuePop(Queue* pq)
{assert(pq);assert(pq->head != NULL);//第一種方法//Queue* cur = pq->head;//if (cur->next == NULL)//{//	free(cur);//	pq->head = pq->tail = NULL;//}/*else{pq->head = cur->next;free(cur);cur = NULL;}*///第二種方法QNode* next = pq->head->next;free(pq->head);pq->head = next;if (pq->head == NULL){pq->tail = NULL;}pq->size--;
}

->5.獲取隊頭元素

//獲取隊頭成員
int QueueFront(Queue* pq)
{assert(pq);assert(pq->head);return pq->head->data;
}

->6.獲取隊尾元素

//獲取隊尾成員
int QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->tail->data;
}

->7.獲取隊列中有效元素個數(shù)

//獲取隊列中有效元素個數(shù)
int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}

->8.查看隊列是否為空

//查看隊列是否為空
bool QueueEmpty(Queue* pq)
{assert(pq);return pq->size == 0; //pq->head == NULL && pq->tail == NULL
}

3.完整代碼

Queue.h

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <stdlib.h>typedef int QDataType;typedef struct QListNode 
{struct QListNode* next;QDataType data;
}QNode;typedef struct Queue
{QNode* head;QNode* tail;QDataType size;
}Queue;//初始化
void QueueInit(Queue* pq);
//清空隊列成員
void QueueDestroy(Queue* pq);
//隊尾插入隊列
void QueuePush(Queue* pq, QDataType x);
//刪除隊隊頭元素,隊列先進先出
void QueuePop(Queue* pq);
//獲取隊頭元素
int QueueFront(Queue * pq);
//獲取隊尾元素
int QueueBack(Queue* pq);
//獲取隊列中有效與元素個數(shù)
int QueueSize(Queue* pq);
//查看隊列是否為空
bool QueueEmpty(Queue* pq);

Queue.c

#include "queue.h"//初始化
void QueueInit(Queue* pq)
{assert(pq);pq->head = pq->tail = NULL;pq->size = 0;
}//銷毀隊列
void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->head;//QNode* cur = pq->head->next;while (cur){/*free(pq->head);pq->head = cur;cur = cur->next;*/QNode* next = cur->next;free(cur);cur = next;}pq->head = pq->tail = NULL;pq->size = 0;
}//插入隊列成員
void QueuePush(Queue* pq, QDataType x)
{QNode* newnode = (QNode*)malloc(sizeof(QNode));if (NULL == newnode){perror("QueuePsuh::malloc");return;}newnode->data = x;newnode->next = NULL;if (pq->head == NULL){assert(pq->tail == NULL);pq->head = pq->tail = newnode;}else{pq->tail->next = newnode;pq->tail = newnode;}pq->size++;
}//刪除隊列成員,隊列先進先出
void QueuePop(Queue* pq)
{assert(pq);assert(pq->head != NULL);//Queue* cur = pq->head;//if (cur->next == NULL)//{//	free(cur);//	pq->head = pq->tail = NULL;//}/*else{pq->head = cur->next;free(cur);cur = NULL;}*/QNode* next = pq->head->next;free(pq->head);pq->head = next;if (pq->head == NULL){pq->tail = NULL;}pq->size--;
}//獲取隊頭成員
int QueueFront(Queue* pq)
{assert(pq);assert(pq->head);return pq->head->data;
}//獲取隊列中有效元素個數(shù)
int QueueSize(Queue* pq)
{assert(pq);return pq->size;
}//獲取隊尾成員
int QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->tail->data;
}//查看隊列是否為空
bool QueueEmpty(Queue* pq)
{assert(pq);return pq->size == 0; //pq->head == NULL && pq->tail == NULL
}

test.c

#include "queue.h"int main()
{Queue st;QueueInit(&st);QueuePush(&st, 1);QueuePush(&st, 2);QueuePush(&st, 3);QueuePush(&st, 4);QueuePush(&st, 5);while (!QueueEmpty(&st)){printf("%d ", QueueFront(&st));QueuePop(&st);}printf("\n");return 0;
}

測試結(jié)果:

http://www.risenshineclean.com/news/9127.html

相關(guān)文章:

  • 北京工程建設交易網(wǎng)標題優(yōu)化
  • 建網(wǎng)站 免費搜索引擎營銷分析
  • 北京市保障性住房建設投資中心網(wǎng)站6搜索引擎下載安裝
  • ASP動態(tài)網(wǎng)站制作國外b站不收費免費2023
  • 大連市建委培訓官方網(wǎng)站微信公眾號營銷
  • 行業(yè)網(wǎng)站開發(fā)運營方案免費推廣平臺排行
  • 煙臺h5網(wǎng)站制作sem優(yōu)化和seo的區(qū)別
  • 什么網(wǎng)站做簡歷比較好seo營銷服務
  • js導入wordpress汕頭seo排名收費
  • 做銀行設計有好的網(wǎng)站參考嗎關(guān)鍵詞工具
  • 怎么樣把以前做的網(wǎng)站刪除希愛力雙效片騙局
  • 網(wǎng)站建設shzanen百度競價查詢
  • 萬網(wǎng)域名管理平臺登錄廣州seo網(wǎng)站推廣平臺
  • 深圳外文網(wǎng)站制作交換免費連接
  • ps做網(wǎng)站大小尺寸短視頻seo推廣隱迅推專業(yè)
  • 上海做網(wǎng)絡推廣濰坊自動seo
  • 24小時自助下單網(wǎng)站搜索引擎付費推廣
  • 帝國cms網(wǎng)站遷移頁面seo是什么意思
  • 小程序制作開發(fā)關(guān)鍵詞排名優(yōu)化教程
  • wordpress 搜索 分類seo站長助手
  • wordpress企業(yè)主題教程seo優(yōu)化員
  • 做 b2b平臺的網(wǎng)站公眾號推廣引流
  • dw做網(wǎng)站投票網(wǎng)址收錄入口
  • 比較好的推廣平臺seo有名氣的優(yōu)化公司
  • 運城 網(wǎng)站制作企業(yè)郵箱賬號
  • 網(wǎng)站建設公司業(yè)務在哪里來手機怎么創(chuàng)建自己的網(wǎng)站平臺
  • b2b電子商務網(wǎng)站推廣銷售新手怎么找客源
  • 長春網(wǎng)站建設工作室seo優(yōu)化一般包括哪些
  • 網(wǎng)站頂部素材沈陽seo排名收費
  • 做食品網(wǎng)站需要什么資質(zhì)嗎公司網(wǎng)站設計公司