- 最後登錄
- 2024-11-13
- 在線時間
- 65 小時
- 註冊時間
- 2010-8-23
- 閱讀權限
- 20
- 精華
- 0
- UID
- 8632710
- 帖子
- 123
- 積分
- 127 點
- 潛水值
- 22263 米
| 以下不是code喔~~- Function mergeSort(Type data[1..n])
- If n <= 1 then return
- Index i, j, k
- For i from 2 to (n / 2) do
- For j from 0 to (n - 1) step (2 * i) do
- Index x, y
- x = min(i, n - j)
- y = min(i, max(0, n - i - j))
- Type left[1..x], right[1..y]
- For k from 1 to x do
- left[k] = data[j + k]
- For k from 1 to y do
- right[k] = data[i + j + k]
- Index p, q, r
- p = q = 1
- r = j
- While p <= x and q <= y do
- If left[p] < right[q] then
- data[r] = left[p]
- p = p + 1
- Else
- data[r] = right[q]
- q = q + 1
- r = r + 1
- While p <= x do
- data[r] = left[p]
- p = p + 1
- r = r + 1
- While q <= y do
- data[r] = right[q]
- q = q + 1
- r = r + 1
- End
複製代碼 ... |
|