contributed by < warrenanson
>
雙系統linux
bash on window 虛擬器(舊版)
不要將 Linux 安裝在虛擬機器上,也不要用雲端主機,否則之後用 perf 一類的工具將無法測量出實際程式效能
:notes: jserv
Your task is to modify the code in queue.h and queue.c to fully implement the following functions.
新增 size 以及 tail
則 q_size 和 q_insert_tail 可以在 內完成
初始化Queue之設定,若malloc失敗則回傳NULL
無法一次釋放掉整個Queue,必須從head到tail一個個釋放
將q->head移動到next,再將prev本身和其value釋放
由於strcpy回傳的長度不含\0
,所以 newh->value所需空間大小要多一
和q_insert_head
差不多
差別在於當q->head
為空時,q->tail = newh
當ㄉq->head
不為空時, q->tail->next = newh;
依照題目要求當Queue為NULL或空時回傳false
以及copy the removed string to *sp
(up to a maximum of bufsize-1 characters, plus a null terminator.)
所以 sp[bufsize - 1] = '\0'
此處要加上\0
若Queue不回空就直接回傳size,可在 內完成
這部分本來的寫法是將value從tail開始依序丟到另一個Queue當中
後來改寫成目前這樣,將指標反轉即可達到效果,不需要額外的空間