根据排序C中的索引数组的数组 [英] Sort an array based on an index array in C
本文介绍了根据排序C中的索引数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想许多并行的数组排序。我排序的qsort一个阵列,我返回一个int数组,指定其原始位置的索引。现在有了这个int数组,我需要其他数组排序。
阵列1:
ZZZ
YYY
DEF
ABC
CDE
XXX
排序后,我得到的指数阵列和阵列进行排序:位置并按Idx阵列
3:ABC
4:CDE
2:DEF
5:XXX
1:YYY
0:ZZZ
现在基于该指数阵列上,我需要排序另一个阵列
A
b
C
ð
Ë
F
,使之成为
D
Ë
C
F
b
一个
非常感谢
解决方案
为(i = 0;我6; ++ I)
SortedArray [IndexArray [I] = AnotherArray [I]
I am trying to sort many arrays in parallel. I sort one array by qsort and I return an int array which specifies the indices of their original positions. Now with this int array, I need to sort other arrays.
Array 1:
zzz
yyy
def
abc
cde
xxx
after sorting, I get the index array and the sorted array:Idx position array
3 : abc
4 : cde
2 : def
5 : xxx
1 : yyy
0 : zzz
Now based on this index array, I need to sort another array
a
b
c
d
e
f
so that it becomes
d
e
c
f
b
a
Thanks a lot
解决方案
for (i=0; i < 6; ++i)
SortedArray[IndexArray[i]] = AnotherArray[i];
这篇关于根据排序C中的索引数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文