Thanks @simpliplant and @boyu0.

@boyu0 
I think it is better if you can write some pseudocode.