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

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



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

"Boyd Stephen Smith Jr." <bss@iguanasuicide.net> writes:

> nl values | sort -k2 | nl | grep value_i
>
> The first column is the new location, 1-based.  The second column is the old 
> location, 1-based.  If your values are numbers, you might use (awk '$3 == 
> value_i') instead of the grep.
>
> nl = O(n)
> sort = O(n lg n)
> grep = O(n)
>
> The whole pipeline is therefore O(n lg n).

Not a bad idea. Thanks for complexity calculus. Would not something like

==
cat file.txt | awk -F" " '{ print $0,$(
for ((i = 1; i < n + 1; i++))
do
echo $i
done
) }'
==
do the trick, file.txt being a text file such as

==
 20 Jan 2010 17:39:42
 .
 .
 .
==
(the syntax errors being not comprised)?

Thanks.

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

Don't take life too seriously; you'll never get out of it alive.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAktkFFUACgkQM0LLzLt8Mhww+QCgiM1ASGf7RRIm5lDJ8yYtEHTt
leUAn2YpIQ+TgWMFCTgDqciLlbWxvPe4
=HaIU
-----END PGP SIGNATURE-----


Reply to: