’待排序数据存储在数组a中(a(1)~ a(n)),要求升序排列
For i = 1 To (n - 1) \ 2
For j = 1 To n - i * 2
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 2): a(j + 2) = t
End If
Next j
Next i
For i = 1 To n \ 2
j = 2 * i - 1
If a(j) > a(j+1) Then t = a(j): a(j) = a(j+1): a(j+1) = t
Next i
For i = 1 To n Step 2
t = a(i): j = i - 1
Do While t < a(j)
a(j + 1) = a(j): j = j - 1
Loop
a(j + 1) = t
Next i
同类型试题
y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2
y = sin x, x∈R, y∈[–1,1],周期为2π,函数图像以 x = (π/2) + kπ 为对称轴
y = arcsin x, x∈[–1,1], y∈[–π/2,π/2]
sin x = 0 ←→ arcsin x = 0
sin x = 1/2 ←→ arcsin x = π/6
sin x = √2/2 ←→ arcsin x = π/4
sin x = 1 ←→ arcsin x = π/2