Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 2.3

COLUMN

Stacks and Recursion

A look at stacks as a replacement for recursion

Issue: 2.3 (December/January 2003)
Author: Thomas Reed
Author Bio: Thomas Reed has been programming as a hobbyist for more than 20 years, and fell in love with the Mac in 1984.
Article Description: No description available.
Article Length (in bytes): 6,371
Starting Page Number: 34
Article Number: 2315
Resource File(s):

Download Icon 2315.zip Updated: 2013-03-11 19:07:57

Related Link(s): None

Excerpt of article text...

The stack is a data structure that is encountered frequently in software design. Although the basic idea of stacks is simple, applications are quite diverse. Stacks provide the foundation for function calls. They can be used to represent a deck of cards in a solitaire game. Undo and redo algorithms are based on stacks. In this article, I will discuss one particular practical application of stacks -- the use of stacks in recursion.

If you are not familiar with stacks, now is the time to flip back to this column in the very first issue of REALbasic Developer. In that issue, Matt Neuburg explained stacks, implementing them using a linked list. Although I will be using arrays to implement the stacks in my examples, the basic idea is the same.

Recursion is a very powerful technique that can be used to solve many different problems. The basic idea of recursion is that a function repeatedly calls itself to come up with a solution. For example, an implementation of the Pow function, used to raise an integer to a certain power, might look like this:

Function Pow(base as integer, exponent as integer) as Integer

if exponent = 0 then

return 1

...End of Excerpt. Please purchase the magazine to read the full article.