contributted by < billqwer1687
>
認真看作業要求,除了提及如何逐步達到要求,還需要進行:
還未達成符合預期目標,請繼續付出!
jserv
實作以下 LIFO FIFO Queue 之功能
qnew: Create a new, empty queue.
qfree: Free all storage used by a queue.
qinserthead: Attempt to insert a new element at the head of the queue (LIFO discipline).
qinserttail: Attempt to insert a new element at the tail of the queue (FIFO discipline).
qremovehead: Attempt to remove the element at the head of the queue.
qsize: Compute the number of elements in the queue.
詳細說明 :
新增了指標tail與變數size,目的是為了讓insert from tail與計算size的時間複雜度為
將queue初始化,且要記得malloc為NULL的狀況
這邊要先free value才能free temp等到queue為空時再將queue給清空
在寫作業的時候忘記將tail指向NULL所以出現了Bug
這邊也是忘記將tail指向NULL
sp[bufsize-1]是為了將'\0'放入字串的尾端,因為strncpy不會在尾端留'\0'
因為有使用變數size儲存queue的大小所以在這裡可以以的時間複雜度求得queue的size
此處queue的反轉參考了以下的資料資料參考,然後在q->tail = q->head的地方打反了,找了一下子
TOTAL 100/100
在trace資料夾中有cmd命令檔案,test會依據這些cmd的命令所回傳的結果去判定程式執行是否正確
待補完
qtest
的行為和裡頭的技巧待補