高普考題庫
96 年 096年公務人員高等考試三級考試暨普通考試・程式語言
申論 2假設我們有一個下列的C/C++語言的資料結構。struct node_type { int value; struct node_type *next; };請用這個資料結構,設計一個queue 的enqueue 與dequeue 程序。struct node_type *enqueue(struct node_type *q, int v);這個程序會把v 加到q 指到的queue 的尾端,並且把新的queue 傳回。struct node_type *dequeue(struct node_type *q, int *vp);這個程序會把q 指到的queue 頭的值,寫到*vp 中,然後把這個頭去掉,再把新的queue 傳回。這兩個程序的complexity 都必須是O(1),而且必須能處理空的queue。你只能使用一個static pointer 變數。(25 分)