[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Sorting elements *and* knowing where each one has been put



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I have some numerical values, i.e. something like

==
value_1
value_2
.
.
.
value_n
==

There are many ways to sort them, but the `sort' command is clearly
appropriate.

The problem is that I need to know where value_i is, before, and
after, the sorting. It can be found easily by keeping in memory where
value_i is before the sorting (for every i, 1<=i<=n), and finding
where value_i is after the sorting, by looking in the sorted numbers
and finding value_i. However, this solution, despite being simple, is
clearly bad on an algorithmic point of view. The best way is
consequently to use the sorting function (which could be, e.g. a
Heapsort, or simply the `sort' command) to know where value_i is
displaced once it has been transformed by the sorting function.

However, I do not know how I can do this with the `sort' function. Is
it even possible? (I considered 1<=i<=n through the whole message.)

Thanks.
- -- 
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- -- 

Don't bite the hand that feeds you.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAktjalAACgkQM0LLzLt8MhxhNwCgjeBPyoWCZOLSRQoVV9R4cI1y
auMAnjRwcjoQ4c7MLBaCtz12MPnVltHe
=NkLy
-----END PGP SIGNATURE-----


Reply to: