資料結構›Ch7 搜尋與排序第 54 題/共 76 題
54. Insertion Sort、Pseudocode
#DS-07-054中Insertion SortPseudocode
- The insertion sort algorithm in the following sorts the elements in arr[0..n-1]. Which of the followings are true?
1 void insertionSort(int arr[], int n)
2 {
3 int i, key, j;
4 for (i = 1; i < n; i++)
5 {
6 /* MISSING CODE */
7 j = i - 1;
8
9 while (j >= 0 && arr[j] <= key)
10 {
11 arr[j + 1] = arr[j];
12 j = j - 1;
13 }
14 arr[j + 1] = key;
15 }
16 }
📄 交大111
▤完整推導請見《WH 資工筆記 · 資料結構》Ch7 搜尋與排序