contributed by < shauming1020
>
homework
轉換程式
測試程式
輸出
*py &= BB2;
而 bfloat16 為 16 bit,因此取 y 的前 16 bit (signed number, exp, mantissa),故 BB2 為 0xffff0000
考慮到以下靜態初始化的 singly-linked list 實作:
其執行結果為:
9547
4579
參照 C 語言程式設計技巧
「靜態」的 linked list
C99 [6.5.2.5] Compound literals
- The type name shall specify an object type or an array of unknown size, but not a variable length array type.
- A postfix expression that consists of a parenthesized type name followed by a braceenclosed list of initializers is a compound literal. It provides an unnamed object whose value is given by the initializer list.
- If the type name specifies an array of unknown size, the size is determined by the initializer list as specified in 6.7.8, and the type of the compound literal is that of the completed array type. Otherwise (when the type name specifies an object type), the type of the compound literal is that specified by the type name. In either case, the result is an lvalue.
將 struct llist *list = cons(cons(cons(cons(NULL, A), B), C), D);
展開如下
Insertion Sort
將第 i 筆資料插入前 i - 1 筆已完成排序好的資料中
#34 *head = sorted;
變數 sorted 為指向已排序好的 list 之 head,因此在最後時必須將其指派給 *head
sorted_insert(&sorted, current);
變數 current 指向尚未完成排序的 list 之 head,將其插入已完成排序的 list 中
考慮下列情況來思考 SS1 和 SS2
(*head)->val >= node->val)
當 head 值比 node 大時,node 應要插入在 head 之前,因此我們可以
node->next = *head
,即 SS1
*head = node
,即 SS2
LeetCode 287. Find the Duplicate Number 給定一個整數序列,其中會有一個數值重複,請找出。
已知條件:
Example 1:
Input: nums = [1,3,4,2,2]
Output: 2Example 2:
Input: nums = [3,1,3,4,2]
Output: 3Example 3:
Input: nums = [1,1]
Output: 1Example 4:
Input: nums = [1,1,2]
Output: 1
考慮以下程式碼是可能的解法:
k | k & bit | nums[k] & bit |
---|---|---|
000 (0) | 0 (c1 = 0) | 1 (c2 = 1) |
001 (1) | 1 (c1 = 1) | 1 (c2 = 2) |
010 (2) | 0 (c1 = 1) | 0 (c2 = 2) |
011 (3) | 1 (c1 = 2) | ? (c2 = 2+?) |
if (CCC) res += bit;