# 2025q1 Homework2 (quiz1+2) contributed by <`Louis-Wup`> # 第 1 週測驗題 ## Q1 ### 解釋程式碼運作的原理 ```c typedef struct list_item { int value; struct list_item *next; } list_item_t; typedef struct { struct list_item *head; } list_t; void list_insert_before(list_t *l, list_item_t *before, list_item_t *item) { list_item_t **p; for (p = &l->head; *p != before; p = &(*p)->next) ; *p = item; item->next = before; } ``` 首先,讓間接指標 `p` 指向 `head` 指標。  之後不斷判斷 `p` 指標指向的指標 是否指向 `before` ,也就是要插入的位置,若不是就將 `p` 指標指向 被指到的指標 所指向的節點的 `next` 指標。   最後讓 `p` 指標指到的指標 改成 指向 `item` 後,並讓 `item` 的 `next` 指向 `before` 。   ### 合併排序操作
×
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