# 2025q1 Homework1 (lab0) contributed by <`junminhong`> {%hackmd NrmQUGbRQWemgwPfhzXj6g %} ## 開發環境 ```shell $gcc --version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 ``` ## 實作 queue.[ch] ### q_new > Commit [e2250279b29606e505f0bb96b98b6099daa4948e](https://github.com/junminhong/lab0-c/commit/e2250279b29606e505f0bb96b98b6099daa4948e) #### 實作想法 - 使用 malloc 分配記憶體位址 - 因為 [C99規格書](https://port70.net/~nsz/c/c11/n1570.html#7.22.3.4) 有提到 malloc 於分配記憶體時會回傳 NULL 或者記憶體位址,所以要處理這個情境 - 使用 list.h 內的 INIT_LIST_HEAD function 進行初始化 ### q_free > Commit [48666cd26a8c100e770399baf4e8d2da945e2d86](https://github.com/junminhong/lab0-c/commit/48666cd26a8c100e770399baf4e8d2da945e2d86) #### 實作想法 - 使用 list.h 內的 list_for_each_safe function 安全的 loop list 的每個 node - 基於 list_for_each_safe 的特性搭配 list.h 內的 list_del function 刪除 node 並且同時釋放記憶體位址 - 最後需要要記得把 head 做釋放 ### q_insert_head