or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
2023q1 Homework1 (quiz1)
contributed by < paintako >
開發環境
測驗一
不用列出上述答案項目,專注於程式碼和背後的原理。
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →解釋程式碼運作原理
取 list 中第一個 entry 作為
pivot
, 並且移除它使用
list_for_each_safe
迭代, 需要注意的是, 並且用itm
作為當前節點, 如果此點小於pivot
, 將此點移到list_less
最後, 反之移到list_greater
中分成左右兩邊後 (
list_less
以及list_greater
), 遞迴的下去呼叫list_sort
,再將 pivot 加回串列中,並用
list_splice
將list_less
加到head
後,pivot
之前再執行list_splice_tail
將list_greater
加回結尾完成排序。改進方案
pivot
挑選問題, 如果原本節點內的排列方式是由大到小, 那此方法的複雜度: \(O(n^2)\)若要改善此問題, 那每次挑
pivot
時可隨機挑選而不是挑固定位置延伸問題
測驗二
與其直接宣告一個
MAX_DEPTH 512
大小的陣列, 不如在需要增加stack top
時在 malloc 一塊新的空間給其使用 ( in heap memory) , 這樣可以避免stack memory
一大塊空間被佔住, 但需要在程式結束前自己手動free
, 原本的作法離開 function 時系統就會自動回收掉list_head stack[MAX_DEPTH]
所佔用的記憶體