Не сортируйте «нужно».Создайте индексный массив, затем отсортируйте его по необходимости.Вы не указали язык, поэтому получаете JavaScript:
var person = [], need = [];
var person = ["E", "B", "A", "C", "D"];
var need = [111, 444, 555, 333, 222];
var index = [];
var i = person.length;
while (i--) {
index.push(i);
}
var comparator = function(a, b) {
var need_a = need[a];
var need_b = need[b];
// For robustness - non-numbers get sorted last:
if (typeof need_a != 'number' || isNaN(need_a)) need_a = -Infinity;
if (typeof need_b != 'number' || isNaN(need_b)) need_b = -Infinity;
if (need_a < need_b) return 1;
if (need_b < need_a) return -1;
return 0;
}
index.sort(comparator);
// at this point, person[index[0]] is the person with the biggest need.
var sorted_person = [];
var i = index.length;
while (i--) {
sorted_person[i] = person[index[i]];
}
// at this point, sorted_person[0] is the person with the biggest need.
console.log(sorted_person);