佇列的鏈式儲存結構及實現

2021-07-24 13:26:28 字數 1400 閱讀 9169

佇列的鏈式儲存結構其實就是線性表的單鏈表,只不過它只能尾進頭出,也稱為鏈佇列。為了操作方便講隊頭指標指向鏈佇列的頭結點,而隊尾指標指向終端節點。

空佇列是這樣

下面使用**演示:

#include

#include

#include

typedef struct node

node,*pnode;

typedef struct queue

queue,*pqueue;

void initqueue(pqueue);

bool addqueue(pqueue,int);

bool deletequeue(pqueue,int *);

bool isempty(pqueue);

void showqueue(pqueue);

int main(void)

void showqueue(pqueue pqueue)

printf("\n");

}bool isempty(pqueue queue)

return

false;

}void initqueue(pqueue queue)

p->pnext =

null;

queue

->front = p;

queue

->rear =

queue

->front;

return;

}bool addqueue(pqueue queue,int e)

p->

data

=e; p->pnext =

null;

queue

->rear->pnext = p;

queue

->rear = p;

return

true;

}bool deletequeue(pqueue queue,int * pval)

pnode p =

queue

->front->pnext;

*pval = p->

data;

printf("刪除的結點是:%d\n",*pval);

if(p==

queue

->rear)

else

free(p);

p =null;

return

true;

}

佇列的鏈式儲存結構及實現

佇列的鏈式儲存結構,其實就是線性表的單鏈表,只不過它只能尾進頭出而已,稱之為鏈佇列。為了操作上的方便,我們將隊頭指標指向鏈佇列的頭結點,將隊尾指標指向終端結點,如下圖所示 空佇列時,頭尾指標都指向頭結點,如下圖所示 鏈佇列的結構為 typedef int qelemtype qelemtype 型別...

佇列的鏈式儲存結構及實現

在之前講解了順序佇列,接下來講解佇列的鏈式儲存結構及實現 在佇列的鏈式儲存中我們將隊頭指標指向單鏈表的頭結點,隊尾指標指向終端節點 在隊列為空時,front和rear都指向頭結點 鏈佇列的結構為 define maxsize 1000 define ok 1 define error 0 defin...

佇列的鏈式儲存結構以及實現

佇列的鏈式儲存結構,其實就是線性表的單鏈表,只不過它只能尾進頭出而已,通常簡稱為鏈佇列。為了操作上的方便,將隊頭指標指向鏈佇列的頭結點,隊尾指標指向終端結點。當隊列為空時,front和rear都指向頭結點。鏈佇列的結構定義如下所示 typedef int qelemtype qnode代表佇列中元素...