数组排序问题

 

给定一个数组A

int A[10]={1,5,6,4,2,0,1,5,9,7};

复制成数组B[]:

int B[];

ArrayCopy(B,A,0,0,WHOLE_ARRAY);

对于数组B进行升序排序:

ArraySort(B,WHOLE_ARRAY,0,MODE_ASCEND);

==============================

以上都没有问题。问题出在下面:

==============================

查找排序后的数组B中的各项在数组A中的位置n:

int n0=0,n;
for(n0=0;n0<10;n0++){

n=ArrayBsearch(sheng,shengxu[n0],WHOLE_ARRAY,n0,MODE_ASCEND);

}

出现错误,因为A中有相同的值。

请问老师,怎么解决这个问题?

 
#define MAXLEN		10
#define NAME_TMP	"bcdef"

int myFind() {
	string C[10] = {"a", "abcde", "abcdef", "abc", "ab", "", "b", "bcdef", "abcdefghi", "abcdefg"};
	int A[10] = {1, 5, 6, 4, 2, 0, 1, 5, 9, 7};
	int B[];
	int i, j, k, m, n;

	ArrayCopy(B,A,0,0,WHOLE_ARRAY);
	ArraySort(B,WHOLE_ARRAY,0,MODE_ASCEND);
	n = ArraySize(A);
	k = 0;
	for (i=0, j=0; i<n; i++, j++) {
		j = ArrayBsearch(A, B[k], WHOLE_ARRAY, j, MODE_ASCEND); 
		if (j == n)		// A中不存在B[k]
			break;
		else {
			m = A[j];
			if (C[m] != NAME_TMP)		// 因为A[]有重复的,继续查找
				continue;
			else				// 找到,退出
				break;
		}
	}
	return(j);
}
原因: