# 2025q1 Homework1 (lab0) contributed by < ```awkai99``` > {%hackmd NrmQUGbRQWemgwPfhzXj6g %} ## 開發環境 ```bash $ gcc --version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 12 On-line CPU(s) list: 0-11 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz CPU family: 6 Model: 158 Thread(s) per core: 2 Core(s) per socket: 6 Socket(s): 1 Stepping: 10 CPU(s) scaling MHz: 18% CPU max MHz: 4500.0000 CPU min MHz: 800.0000 BogoMIPS: 5199.98 Virtualization: VT-x L1d cache: 192 KiB L1i cache: 192 KiB L2 cache: 1.5 MiB L3 cache: 12 MiB NUMA node(s): 1 NUMA node0 CPU(s): 0-11 ``` ## 針對佇列操作的程式碼實作 ### q_new() * **函式用途**:建立新的「空」佇列 * **程式碼**:[Commit b62c9b4](https://github.com/awkai99/lab0-c/commit/b62c9b44e2307641d77975ab3d01d6f222ccb2ee) ### q_free() * **函式用途**:釋放佇列所佔用的記憶體 * **程式碼**: ### q_insert_head() * **函式用途**:在佇列開頭 (head) 插入 (insert) 給定的新節點 (以 LIFO 準則) ### q_insert_tail() * **函式用途**:在佇列尾端 (tail) 插入 (insert) 給定的新節點 (以 FIFO 準則) ### q_remove_head() * **函式用途**:在佇列開頭 (head) 移去 (remove) 給定的節點 ### q_remove_tail() * **函式用途**:在佇列尾端 (tail) 移去 (remove) 給定的節點 ### q_size() * **函式用途**:計算目前佇列的節點總量 ### q_delete_mid() * **函式用途**:移走佇列中間的節點,詳見 LeetCode 2095. Delete the Middle Node of a Linked List ### q_delete_dup() * **函式用途**:在已經排序的狀況,移走佇列中具備重複內容的節點,詳見 LeetCode 82. Remove Duplicates from Sorted List II ### q_swap() * **函式用途**:交換佇列中鄰近的節點,詳見 LeetCode 24. Swap Nodes in Pairs ### q_reverse() * **函式用途**:以反向順序重新排列鏈結串列,該函式不該配置或釋放任何鏈結串列節點,換言之,它只能重排已經存在的節點 ### q_reverseK() * **函式用途**:類似 q_reverse,但指定每 k 個節點為一組,進行反向順序排列,詳見 LeetCode 25. Reverse Nodes in k-Group ### q_sort() * **函式用途**:以遞增順序來排序鏈結串列的節點,可參閱 Linked List Sort 得知實作手法 ### q_ascend() 參閱 LeetCode 2487. Remove Nodes From Linked List,注意節點間的順序 ### q_descend() ### q_merge() 合併所有已排序的佇列,並合而為一個新的已排序佇列,詳見 LeetCode 23. Merge k Sorted Lists
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up