contributed by < JimmyZhan070100
>
linux2021
**indirect
取得 list->head
的 address 後,便可以快速對 target
進行刪除註: 此段程式並沒有將
target
的記憶體釋放,僅有將它不再串接
LLL = (c), left = &((*left)->next)
AAA = (e), &right
BBB = (c), &left
CCC = (b), list_concat(&result, pivot); list_concat(&result, right)
list_make_node_t
和 list_free(&list)
的實做,在此補上list_add_node_t
line 6 : l *left = right;
line 6 ~ 9 : 選擇 pivot , 從要排序的串列中選擇一個數字當作比較數值的基準,此處使用 list 的第一個 node 作為 pivot
line 15 : list_add_node_t(n->value > value ? AAA : BBB, n)
:
跳出迴圈後就會形成兩條 lists ( left & right )
接著進入遞迴進行排序,最後排序成兩條由小到大的 lists
再藉由 list_concat
將兩串列接起來
CCC = (b) list_concat(&result, pivot); list_concat(&result, right)
根據 random 的敘述
The srandom() function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by random(). These sequences are repeatable by calling srandom() with the same seed value. If no seed value is provided, the random() function is automatically seeded with a value of 1.
可以得知當 srandom()
的 argument 可以設定 seed 以產生偽亂數的序列,若沒有給予 seed value ,那麼 random()
將會自動將 seed 設為 1。
由於在程式中,並沒有設定 seed value ,所以 default 狀態下 seed = 1 ,才導致每次的輸出結果都一樣。
為了每次都能夠產生不同的 seed,可以使用 time()
time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
根據敘述,我們可以得到從標準計時點(一般是 UTC 1970年1月1日午夜)到目前時間的秒數。
time(NULL)
的時間可以發現 time(NULL)
的資料型別為 time_t
,繼續尋找他的宣告,可在 time_t.h
找到這段 typedef __time_t time_t;
接著繼續查詢,便可在 types.h
找到下方這段 :
# define __time64_t __time_t
根據 GNU C Library 的解釋 :
These single-time configurations only have a 64-bit time_t and related functions, which can handle dates beyond 2038-01-19 03:14:07 (aka Y2038).
在 Visual Stduio 2019 可找到關於 time_t
和 __time64_t
的敘述 :
在 Visual Studio 2005 之前的 Visual C++ 和 Microsoft C/c + + 版本中, time_t 是 long int (32 位) ,因此無法用於過去3:14:07 年1月19日2038(UTC)的日期。 time_t 現在預設等同於 __time64_t,但定義 _USE_32BIT_TIME_T 會將 time_t 變更為 __time32_t,並強制許多時間函式呼叫接受 32 位元 time_t 的版本。
由此可得知,為了表示更長的時間,編譯器廠商可透過改變資料型態來保存時間 (在此以 Visual Stduio 為例)
那麼該如何印出時間呢?
在 time_t-cpp reference 透過 stdint.h
和 intmax_t
來強制轉型。
輸出結果