国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

隊列

2019-11-08 03:14:28
字體:
來源:轉載
供稿:網友

   隊列特性:先進先出(FIFO)——先進隊列的元素先出隊列。

  隊列有下面幾個操作:

InitQueue()    ——初始化隊列EnQueue()          ——進隊列DeQueue()          ——出隊列IsQueueEmpty() ——判斷隊列是否為空IsQueueFull()     ——判斷隊列是否已滿

     隊列數據結構:

   typedef struct queue  {          int queuesize;   //數組的大小          int head, tail;  //隊列的頭和尾下標          int *q;          //數組頭指針  }Queue;

InitQueue()   ——初始化隊列

void InitQueue(Queue *Q){        Q->queuesize = 8;        Q->q = (int *)malloc(sizeof(int) * Q->queuesize); //分配內存        Q->tail = 0;        Q->head = 0;}

這樣有個缺陷,空間利用率不高。采用循環隊列:

EnQueue() ——進隊列

void EnQueue(Queue *Q, int key){        int tail = (Q->tail+1) % Q->queuesize; //取余保證,當quil=queuesize-1時,再轉回0        if (tail == Q->head)                   //此時隊列沒有空間        {            PRintf("the queue has been filled full!");        }        else        {            Q->q[Q->tail] = key;            Q->tail = tail;        }}

DeQueue() ——出隊列

int DeQueue(Queue *Q){        int tmp;        if(Q->tail == Q->head)     //判斷隊列不為空        {            printf("the queue is NULL/n");        }        else        {            tmp = Q->q[q->head];            Q->head = (Q->head+1) % Q->queuesize;        }        return tmp;}

IsQueueEmpty()——判斷隊列是否為空

int IsQueueEmpty(Queue *Q){        if(Q->head == Q->tail)        {            return 1;        }        else        {            return 0;        }}

IsQueueFull()——判斷隊列是否已滿

int IsQueueFull(Queue *Q){    if((Q->tail+1)% Q->queuesize == Q->head)    {        return 1;    }    else    {        return 0;      }} 
上一篇:linux常用命令

下一篇:數塔 HDU - 2084

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东乌珠穆沁旗| 磐石市| 南部县| 庆阳市| 长泰县| 南宁市| 革吉县| 通化县| 辽阳市| 兴宁市| 东明县| 平塘县| 洛浦县| 修水县| 共和县| 夏邑县| 安义县| 海晏县| 潼南县| 阳东县| 通许县| 红原县| 榕江县| 平安县| 庆安县| 舞阳县| 杭锦旗| 柏乡县| 阳山县| 遂宁市| 瑞安市| 满洲里市| 镇巴县| 尉犁县| 顺义区| 武义县| 马山县| 水城县| 津市市| 蒙城县| 封丘县|