When handling my Algorithm Homework, I found there are no packages providing a simple macro to draw a sorting network in LaTeX. So I spent some time and wrote a macro to help.
You can get the tex code from here(updated below). It is tested under TexLive 2009/Archlinux. A sample sorting network drawn by this code is as follows, which is taken from Figure 27.12, CLRS book 2nd Edition.
This macro requires Tikz, forarray(updated below) and tokenizer packages. But in fact I think only the requirement for Tikz is necessary, and the needs for forarray and tokenizer can be eliminated by using LaTeX primitives.
B.T.W. This is my first LaTeX macro. I am still not familiar with macros in LaTeX and have to remind myself that this is just a macro again and again to get rid of the willing to use variables. Maybe I should do some more improvements to make it a sty file so it can be used like a package. But what ever, it works now and just fits my requirements. So I decide to leave it as it is.
##UPDATE Oct. 15, 2010##
I rewrote the code and removed the requirement for forarray package, because forarray package has a collision on \ForEach command with algorithm2e package.
You can get the updated tex file here.
##UPDATE May 8, 2011##
I moved the code to github. You can check it out here.