I am writing a program in C that involves many calls to a function that returns the height of a binary tree. Initially I used recursion to do it, but that has soon come back to bite me because I am getting stack overflow errors (not due to infinite recursion). To fix this, I am attempting to modify the function to not use recursion and use iteration instead. Yes, it is possible to do this with a stack/queue, but I would much prefer to not have to.
I found a website that gives code that traverses the tree without recursion or stacks. Here is the link: http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/
I have attempted to modify it so that instead of printing out each node, it measures the max depth, but I am not sure how I would do that. How would I do this.
The code that you've linked to seems like it works by modifying the tree to convert it into a threaded binary tree. This is a binary tree where each node that has a missing child pointer, rather than storing a null pointer, instead stores a pointer to its inorder predecessor or successor (depending on whether it's missing a left or a right subtree).
This allows you to navigate the entire tree without needing any auxiliary storage space. To descend down into a subtree, you proceed as you normally do. To climb up to a parent node, if your current node is a left child, then keep track of the original node v, then descend down the right child until you, in the course of doing so, follow a thread back up to v's parent, which you can recognize because it will have v as a left child. (You can do a similar trick for right children).
The code that you've linked to works by starting off with a regular old binary tree and lazily inserting and then removing the threads as it walks over it. It's a good exercise to trace through the code knowing how to descend upward and downward by following threads and keeping track of when the threads are added and removed.
To directly answer your question: yes, it's possible to keep track of the maximum depth of any node in the tree. To do so, modify the search algorithm that works by inserting and removing threads, keeping track of the depths of the nodes that you encounter and being careful to adjust them as you step upwards or downwards in the tree.
That being said, I've rarely seen this done in practice. It doesn't play well with multithreading (which has nothing to do with the threads described here), for example. It's a great exercise, though!