帮我输出A,B,C的值Input: An array A[1, ..., n], n >= 1, and k >= max(A), A= {2, 4, 0, 3, 4, 2} Output: An array B[1, ..., n], where the alements of A are sorted into ascending order. COUNTING-SORTING (A, k) 1. reserve memory for the array B[1, ..., n] 2. reserve memory for the array C[0, .., k] // Temporary auxiliary array 3. for i=0 to k 4. C[i] = 0 5. for j=1 to length(A) 6. C[A[j]] = C[A[j]]+1 7. for i=1 to k 8. C[i] = C[i]+C[i-1] 9. for j = length(A) downto 1 10. B[C[A[j]]] = A[j] 11. C[A[j]] = C[A[j]]-1 12. return B
时间: 2023-04-06 20:00:31 浏览: 103
java 输入3个数a,b,c,按大小顺序输出的实例讲解
Output: 数组B[1, ..., n],其中A的元素按升序排序。
COUNTING-SORTING (A, k)
1. 为数组B[1, ..., n]分配内存
2. 为数组C[0, .., k]分配内存 // 临时辅助数组
3. 对于i从0到k
4. C[i] = 0
5. 对于j从1到A的长度
6. C[A[j]] = C[A[j]] + 1
7. 对于i从1到k
8. C[i] = C[i] + C[i-1]
9. 对于j从A的长度到1
10. B[C[A[j]]] = A[j]
11. C[A[j]] = C[A[j]] - 1
12. 返回B
阅读全文