Subj : Re: Are recursive functions ever needed? To : comp.programming From : Simo Melenius Date : Mon Oct 03 2005 10:24 pm Tatu Portin writes: > Well, my problem here seems to be lack of good examples where > recursion is needed. Would anybody provide some? Well, think of quicksort. As others have pointed out, you can generally simulate the effect of recursion with a loop plus a stack. And that it's often a choice about which-fits-best. But as an example, quicksort the algorithm is inherently of recursive nature. It applies itself again to finish its own job -- that's just the way it works. When programming quicksort it's definitely best expressed as a self-recursive function, because that better reflects its nature. The reader should feel free to try to implement an iterative quicksort that's somehow "more iterative" than a straight-forward translation into a loop that uses a stack/list to keep track of the boundary indexes/nodes. That should help in seeing something, I hope. HTH, S -- firstname.lastname@iki.fi -- Today is the car of the cdr of your life. .