二、利用鏈結串列(Linked list)實做佇列(Queues),給予如下鏈結串列節點及佇列定義,front 指標指在串列第一個節點,rear 指標指在串列最後一個節點,請使用 C 語言完成 insert(pq, x)程序,將整數值 x 加入(Insert)到佇列,程式需檢查佇列加入前是否為空的鏈結串列,可使用函數 getnode() 配置(Allocate)一新節點。

詳解 (共 2 筆)
詳解
insert(pq, x)
struct queue *pq;
int x;
{
NODEPTR p;
p=getnode();
p->info = x;
p->next=NULL;
if(pq->front==NULL) pq->front = p;
else pq->rear->next=p;
pq->rear=p;
}
詳解
