Algorithm modification

 There is some thing wrong with finding the maximum element. I modified it.