先上圖,以圖服人:
上**:
標頭檔案linkqueue.h:
/*linkqueue.h*/
#ifndef linkqueue_h_included
#define linkqueue_h_included
#include #include #include #include #include #include typedef int lqelementtype;
typedef struct node
lnode,*pnode;
typedef struct linkqueue
lqueue,*pqueue;
pqueue initiatequeue(pqueue lq);/*初始化佇列*/
void destroyqueue(pqueue lq);/*銷毀佇列*/
void showqueue(pqueue lq);/*列印佇列2*/
bool clearqueue(pqueue lq);/*清空佇列*/
bool emptyqueue(pqueue lq);/*判斷佇列是否為空*/
bool enqueue(pqueue lq,lqelementtype value);/*隊尾入隊*/
bool dequeue(pqueue lq,lqelementtype *tmp);/*隊首出隊*/
bool getfront(pqueue lq,lqelementtype *tmp);/*獲取隊首元素*/
int queuesize(pqueue lq);/*返回佇列長度*/
#endif // linkqueue_h_included
原始檔test.c:
/*test.c*/
/* name:純c語言實現鏈式佇列的相關操作
author:刁肥宅
date: 06/08/18 17:49
description:一切盡在注釋中!
*/#include "linkqueue.h"
int main()
for(i = 0;i < randomoperatingsize;i ++)
else
}int n = queuesize(lq);
printf("queuesize() = %d\n",n);
showqueue(lq);
printf("\n\n");
/*display(ltmp);*/
dequeue(lq,&firstkey);
printf("firstkey = %d\n",firstkey);
if(getfront(lq,&firstkey))
printf("after dequeue,firstkey = %d\n\n",firstkey);
else
printf("getfront error.\n");
printf("enqueuefrequency = %d,dequeuefrequency = %d\n",enqueuefrequency,dequeuefrequency);
clearqueue(lq);
int n2 = queuesize(lq);
printf("queuesize() = %d\n",n2);
destroyqueue(lq);
int n1 = queuesize(lq);
printf("queuesize() = %d\n",n1);
if(lq->front->next == null)
printf("destroyqueue succeed\n");
else
/*lq2 = initiatequeue(lq2);
randomoperatingsize = rand() % 1000 + 1;
for(i = 0;i < randomoperatingsize;i ++)
for(i = 0;i < randomoperatingsize;i ++)
else
}n2 = queuesize(lq2);
printf("queuesize() = %d\n",n2);
if(getfront(lq2,&firstkey))
printf("key = %d\n\n",firstkey);
else
printf("getfront error.\n");
showqueue(lq2);
printf("enqueuefrequency = %d,dequeuefrequency = %d\n",enqueuefrequency,dequeuefrequency);
*/printf("\n");
printf("the screen will be closed in 60 seconds.\n");
sleep(1000 * 60);
return 0;
}pqueue initiatequeue(pqueue lq)
lq->front->next = null;
return lq;
}bool emptyqueue(pqueue lq)
bool enqueue(pqueue lq,lqelementtype value)
return true;
}bool dequeue(pqueue lq,lqelementtype *tmp)
void destroyqueue(pqueue lq)
/*solution 2(badly function):
while(lq->front != null)
*/lq->front->next = lq->rear->next = null;
/*lq->front = lq->rear;*/
}bool clearqueue(pqueue lq)
void display(pqueue lq)
while(lq->front != lq->rear) }
}void showqueue(pqueue lq)
}bool getfront(pqueue lq,lqelementtype *tmp)
int queuesize(pqueue lq)
return id;
}
刁肥宅手筆 純C語言實現堆式串主要操作
標頭檔案hstring.h hstring.h ifndef hstring h included define hstring h included include include include define defaultsize 30 typedef struct hstring endif...
C語言實現鏈式佇列
鏈式佇列,簡稱 鏈佇列 即使用鍊錶實現的佇列儲存結構。鏈式佇列的實現思想同順序佇列類似,只需建立兩個指標 命名為 top 和 rear 分別指向鍊錶中佇列的隊頭元素和隊尾元素,如下圖所示 所示為鏈式佇列的初始狀態,此時佇列中沒有儲存任何資料元素,因此 top 和 rear 指標都同時指向頭節點。在建...
鏈式佇列 C語言實現
鏈式佇列的儲存結構 我們知道,佇列是操作受限制的線性表,佇列有隊頭和隊尾,插入元素的一端稱為隊頭,刪除元素的一端稱為隊尾。練市佇列的隊頭指標指向當前佇列的隊頭結點位置,隊尾指標指向佇列的當前隊尾結點位置。對於不帶頭結點的鏈式佇列,出佇列時可直接刪除隊頭指標所指的結點,因此,鏈式佇列不帶頭結點更方便。...