| View previous topic :: View next topic |
| Author |
Message |
Daniel Shawul
Joined: 14 Mar 2006 Posts: 2285 Location: Ethiopia
|
Post subject: how to print tree non-recursively Posted: Fri Feb 24, 2012 2:43 am |
|
|
So my mind is stuck right now and I can't seem to convert a tail-recursive (I think) tree printing function to a recursive equivalent. It is supposed to print something like:
| Code: |
1.e2e4 2.e7e5 3.d2d4
..............3.d2d3
..............3.a2a3
.......2.d7d5
.......2.d7d6
..
..
1.e2e3 2.e7e5
2.d7d5
|
The nodes of the tree has child and sibling pointers, so in a recursive format the printing function is
| Code: |
void print_node(Node* n) {
Node* cur = n->child;
while(cur) {
if(cur->child)
print_node(cur->child);
else
printf_with_proper_offset(cur);
cur = cur->sibling;
}
}
|
How do you convert that to iterative with out using a stack if possible ? _________________ https://sites.google.com/site/dshawul/
https://github.com/dshawul |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|