my code for book Alg