Home > Articles > Programming > C/C++

Thinking Recursively with C++

  • Print
  • + Share This
Algorithms can often be implemented recursively or nonrecursively; the decision rests with the programmer, who might shy away from a recursive solution because the algorithm might not terminate or that performance might be poor. In reality, recursion can allow for very elegant code as well as facilitating an interesting and economical type of code reuse. Software consultant Stephen B. Morris explores this interesting topic with a data-centric application drawn from the field of networking.
Like this article? We recommend

Like this article? We recommend

Recursion is a powerful technique for producing simple algorithms. It can be used to handle data-intensive operations, such as processing network management data. In this article, I use recursion to handle the processing of nested data elements from a network management application. This is just one domain where this approach can be used.

The Takeaway

Recursive solutions are sometimes rejected based on unfounded fears concerning infinite loops or poor performance. In reality, recursive solutions can be highly elegant, easy to implement, and easy to maintain. This article shows an example of a recursive C++ solution as well as a description of the tradeoffs, advantages, and disadvantages of this important design technique.

Here’s my software design philosophy: if it’s simple, it works, it’s reasonably efficient, and it’s maintainable, it’s good code!

As usual, let’s now get the background information out of the way!

  • + Share This
  • 🔖 Save To Your Account