First page Back Continue Last page Graphics
Sorting numbers
Sort n integers in increasing order.
Create n chares, each keeping one number.
In every odd iteration chares numbered 2i swaps with chare 2i+1 if required.
In every even iteration chares 2i swaps with chare 2i-1 if required.
After each iteration all chares report to the mainchare. After everybody reports mainchares signals next iteration. Sorting completes in n iterations.