Strange. This fellow has now asked exactly the same homeworkquestion on a number of different forums . . . It would have been much easier to just “figure it out.”
I would assume that an application of such an algorithm is a stable of introductory CS or programming courses everywhere. It would not surprise me to find (multiple) such questions in the various venues that people tend ask them.