completed Algo1.7