contributed by < gaberplaysgame > 測驗 1 測驗 2 Timsort 為合併了插入排序與合併排序的混合排序演算法,在排序開始前會把資料分為一個又一個的 Run (區塊),針對每個 Run 的大小來去決定要利用插入排序或合併排序。一般而言長度小於64的小區塊使用插入排序,大於的則使用合併排序。 Run 在 Timsort 中為已經排序(遞增)的區塊,若是所遇到的區塊為遞減的形式,則會強制將區塊反轉轉為遞增形式,這點可以在下方程式碼窺見: if (cmp(cur, next)) { while (next < last && cmp(cur, next)) {
3/30/2023contributed by <gaberplaysgame> 開發環境 $ gcc --version gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.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
3/20/2023contributed by < gaberplaysgame > 測驗 1 原理 uint64_t next_pow2(uint64_t x) { x |= x >> 1; x |= x >> 1; x |= x >> 1; x |= x >> 1;
3/14/2023contributed by < gaberplaysgame > 開發環境 $ gcc --version gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.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
2/28/2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up