ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to print tree non-recursively
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Daniel Shawul



Joined: 14 Mar 2006
Posts: 2285
Location: Ethiopia

PostPost subject: how to print tree non-recursively    Posted: Fri Feb 24, 2012 2:43 am Reply to topic Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Subject Author Date/Time
how to print tree non-recursively Daniel Shawul Fri Feb 24, 2012 2:43 am
      Re: how to print tree non-recursively Ron Murawski Fri Feb 24, 2012 5:17 am
            Re: how to print tree non-recursively Daniel Shawul Fri Feb 24, 2012 6:00 am
      Re: how to print tree non-recursively Heiner Marxen Fri Feb 24, 2012 8:58 pm
            Re: how to print tree non-recursively Daniel Shawul Fri Feb 24, 2012 11:26 pm
      Solution found. Daniel Shawul Sat Feb 25, 2012 5:25 am
            Re: Solution found. Daniel Shawul Tue Feb 28, 2012 7:12 pm
                  Re: Solution found. Karlo Bala Jr. Tue Feb 28, 2012 8:24 pm
                        Re: Solution found. Daniel Shawul Tue Feb 28, 2012 8:48 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
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




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads