http://www.geeksforgeeks.org/tag-sort/
- Tag Sort allows sorting an integer array after tagging it with original object.
- In turn, we only swap the tag array integers instead of large array of objects.
- The actual elements are not being changed during the sort process. The positions in the tag array are being changed so they will hold the correct ordering of the elements when they are sorted.
public
static
void
tagSort(Person persons[],
int
tag[])
{
int
n = persons.length;
for
(
int
i=
0
; i<n; i++)
{
for
(
int
j=i+
1
; j<n; j++)
{
if
(persons[tag[i]].getSalary() >
persons[tag[j]].getSalary())
{
// Note we are not sorting the
// actual Persons array, but only
// the tag array
int
temp = tag[i];
tag[i] = tag[j];
tag[j] = temp;
}
}
}
}