#include
#include
#include
//佇列不提供遍歷功能,只有隊頭和隊尾能夠被外界訪問
//頭結點端做隊頭和隊尾都行
struct person
;//結點結構體
struct queuenode
;//佇列結構體
struct lqueue
;typedef
void
* linkqueue;
//初始化佇列
linkqueue init_linkqueue()
myqueue->pheader.next=
null
; myqueue->m_size =0;
myqueue->ptail =
&myqueue->pheader;
return myqueue;
}//入隊
void
push_linkqueue
(linkqueue queue,
void
* data)
if(data ==
null
)//本質 尾插
struct lqueue * myqueue = queue;
struct queuenode * mynode = data;
//更改指標指向
myqueue->ptail->next = mynode;
mynode->next =
null
;//更新新的尾結點
myqueue->ptail = mynode;
myqueue->m_size++;}
//出隊
void
pop_linkqueue
(linkqueue queue)
struct lqueue * myqueue = queue;
//本質 頭刪
if(myqueue->m_size ==0)
if(myqueue->m_size ==1)
//記錄第乙個有資料的結點
struct queuenode * pfirst = myqueue->pheader.next;
//更改指標指向 pf丟失
myqueue->pheader.next = pfirst->next;
myqueue->m_size--;}
//返回佇列大小
intsize_linkqueue
(linkqueue queue)
struct lqueue * myqueue = queue;
return myqueue->m_size;
}//判斷是否為空
intisempty_linkqueue
(linkqueue queue)
struct lqueue * myqueue = queue;
if(myqueue->m_size ==0)
return0;
}//返回隊頭
void
*front_linkqueue
(linkqueue queue)
struct lqueue * myqueue = queue;
return myqueue->pheader.next;
}//返回隊尾
void
*back_linkqueue
(linkqueue queue)
struct lqueue * myqueue = queue;
return myqueue->ptail;
}//銷毀佇列
void
destroy_linkqueue
(linkqueue queue)
free
(queue)
; queue=
null;}
void
test1()
c語言佇列的鏈式儲存
佇列的鏈式儲存的一種實現方法就是簡化版的線性鍊錶 include include typedef struct node 結點結構 node,linklist typedef struct 佇列的鍊錶結構 linkqueue void create queue linklist l 佇列的建立 r ...
佇列鏈式儲存
ifndef status h define status h define false 1 define true 1 define ok 1 define error 0 typedef int elemtype typedef int status endif ifndef stack h d...
佇列的鏈式儲存
include include include typedef int elemtype typedef struct qnodequeuenode,queuenodeptr typedef struct qlistlistqueue,listqueueptr listqueueptr initqu...