contributed by <justin871030
>
q_new
: Create a new, empty queue.q_free
: Free all storage used by a queue.q_insert_head
: Attempt to insert a new element at the head of the queue (LIFO discipline).q_insert_tail
: Attempt to insert a new element at the tail of the queue (FIFO discipline).q_remove_head
: Attempt to remove the element at the head of the queue.q_size
:Compute the number of elements in the queue.q_reverse
: Reorder the list so that the queue elements are reversed in order. This function should not allocate or free any list elements (either directly or via calls to other functions that allocate or free list elements.) Instead, it should rearrange the existing elements.Two of the functions: q_insert_tail
and q_size
should be operated in time .
queue.h
為了使 q_insert_tail
and q_size
兩個function可以維持在 ,宣告 tail
, size
兩個變數儲存資訊。
q_new
q_free
使用指標配合while迴圈逐步釋放每個節點的空間。
q_insert_head
在每次要求空間時都要檢查是否為 NULL
,假如為 NULL
要回傳 false
,同時釋放已經索取的空間。
q_insert_tail
使用 q_size
使 q_insert_tail
維持在 。
q_remove_head
q_size
題目要求在完成,利用先前宣告的 size
完成這個目標。
q_reverse
目標是翻轉整個list,首先先排除不需翻轉的情形,
接下來,把 q->tail
指向 q->head
原先的位置,
用while迴圈逐個反轉節點指針的指向。
100/100
尚未熟悉Linux的操作,加上好一陣子未碰C語言,debug比想像中花上更多時間。
認真看作業要求,除了提及如何逐步達到要求,還需要進行:
還未達成符合預期目標,請繼續付出!