× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



where I'm using recursion though, it would have been nearly impossible to
duplicate the process without it.
Recursion removal is quite common.  For example, here is a bit of C code to
traverse a binary tree (using recursion)

traverse( struct node *t)  {
    if (t != z)  {
        visit(t);
        traverse(t->left);
        traverse(t->right);
    }
}

By replacing the recursion code with a stack, the following non-recursive
implementation can be made:
traverse(struct node *t) {
        push(t);
        while (!stackempty()) {
            t = pop();
            visit(t);
           if (t->right != z) push(t->right);
           if (t->left != z) push(t->left);
        }
}

If you are interested in reading all the gory details, this bit is from
'Algorithms in C' by Robert Sedgewick.  I use code similar to the above to
traverse nodes in an XML document.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.