[题目分析]题目要求按B数组内容调整A数组中记录的次序可以从i=开始检查是否B[i]=i如是则A[i]恰为正确位置不需再调否则B[i]=k≠i则将A[i]和A[k]对调B[i]和B[k]对调直到B[i]=i为止
void CountSort (rectype A[]int B[])
//A是个记录的数组B是整型数组本算法利用数组B对A进行计数排序
{int ijn=;
i=;
while(i<n)
{if(B[i]!=i) //若B[i]=i则A[i]正好在自己的位置上则不需要调整
{ j=i;
while (B[j]!=i)
{ k=B[j]; B[j]=B[k]; B[k]=k; // B[j]和B[k]交换
r=A[j];A[j]=A[k]; A[k]=r; } //r是数组A的元素类型A[j]和A[k]交换
i++;} //完成了一个小循环第i个已经安排好
}//算法结束
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []