倒置算法

algorithm for inversion