|
From: Jaap de W. <wo...@Ne...> - 2003-02-14 12:22:02
|
> -----Original Message-----
> From: Ioannis Vranos [mailto:no...@ho...]
> Sent: Friday, February 14, 2003 07:25 AM
> To: dev...@li...
> Subject: Re: [Dev-C++] recursion
>=20
>=20
> -------Original Message-------
> =20
> From: Santiago
> Date: =D0=E1=F1=E1=F3=EA=E5=F5=DE, 14 =
=D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2003 5:53:20 =F0=EC
> To: dev-cpp-users-list
> Subject: [Dev-C++] recursion
> =20
> Hello all,
> Simple one: how often, critical, and necessary is the usage=20
> of C++ recursion
> in the "real world" programming field?
> =20
> =20
> =3D=3D> It has its uses, but try to avoid using it. Use loops=20
> instead (usually
> iteration).
> =20
> =20
> =20
> Ioannis Vranos
Iteration is usefull when you have to make more of the same (iterative)
operations on the result of itself, before you have your result.
A traditional example of anything which can't be solved without =
iteration is
the resolving of a regular expression.
But of course there are more simple things which are far less complex =
using
iteration as by loops.
As an example creating a hex string on stream.
void ToHex(ostream &rstr, unsigned int n)
{
const char *HexChars =3D "0123456789ABCDEF";
if (n >=3D 16)
{
ToHex(rstr, n/16);
ToHex(rstr, n%16);
}
else
{
rstr << HexChars[n];
}
}
Jaap=20
|