contributed by < ioksengtan
>
q_new
: 建立新的「空」佇列
q_size
: 計算目前佇列的節點總量q_insert_head
: 在佇列開頭 (head) 插入 (insert) 給定的新節點 (以 LIFO 準則)q_insert_tail
: 在佇列尾端 (tail) 插入 (insert) 給定的新節點 (以 FIFO 準則)
q_remove_head
: 在佇列開頭 (head) 移去 (remove) 給定的節點
q_remove_tail
: 在佇列尾端 (tail) 移去 (remove) 給定的節點q_free
: 釋放佇列所佔用的記憶體q_reverse
: 以反向順序重新排列鏈結串列,該函式不該配置或釋放任何鏈結串列節點,換言之,它只能重排已經存在的節點q_delete_mid
: 移走佇列中間的節點
q_delete_dup
: 在已經排序的狀況,移走佇列中具備重複內容的節點
q_swap
: 交換佇列中鄰近的節點
q_sort
: 以遞增順序來排序鏈結串列的節點Improve your writing! It is supposed to be an official document.
:notes: jserv
Thanks a lot jserv for feedback.
I will continue refining my documentation.
:notes: ioksengtan
list_for_each
reference: https://myao0730.blogspot.com/2016/12/linux.html
using provided list_add() in list.h
reuse list_add_tail in list.h
Corruption detected:
No Corruption detection:
Revised implementation of q_insert_tail
You must explain your observations and reactions.
:notes: jserv
Thanks alot jserv for feedback,
I am cooking those information then document it later.
:notes: ioksengtan
Then there is no corruption
(1) list_add_tail(&(ele->list), head);
(2) list_add_tail(&ele->list, head);
using (1), will fail the static analysis when git commit.
Following implementation is wrongful, causing segmentation fault.
when number is even (N=4)
if front->next = end, remove node3
when number is odd (N=3)
if front = end, remove node2
worst case:
看到一些同學實作quick sort有遇到效能的問題。
複習了sort 的時空複雜度,的確quick sort 的最差情境會是N^2。
merge sort原理: