home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!pipex!warwick!coventry!champion
- From: champion@cch.coventry.ac.uk (Alun)
- Subject: Re: Printing out trees
- Message-ID: <BxG3py.LoA@cck.coventry.ac.uk>
- Sender: news@cck.coventry.ac.uk (news user)
- Nntp-Posting-Host: cc_sysh
- Organization: Coventry University, Coventry, UK.
- References: <gezTJc_00VQsAo9Vpl@andrew.cmu.edu>
- Date: Mon, 9 Nov 1992 10:56:21 GMT
- Lines: 28
-
- In article <gezTJc_00VQsAo9Vpl@andrew.cmu.edu> rickr+@CMU.EDU (Richard Dale Romero) writes:
- ~Does anyone have code for printing out arbitrary binary trees,
- ~ie, not necessarily full, can have 0, 1 or 2 children?
- ~
- ~Any sort of method or strategy would be nice, doesn't even
- ~really have to be code. I'm just stumped for a nice, efficient
- ~way to do it--everything I've tried has been ugly.
-
-
- print(Tree* tree)
- {
- if(tree == 0)
- return;
- print(tree->left);
- printf("%d\n", tree->val);
- print(tree->right);
- }
-
- Does this look okay ??
- By realigning the print and printf() statements you could print the
- tree in any order. :-}
- Depends on how your tree is sorted (if indeed it is sorted at all).
-
- -Alun
-
- --
- A.Champion | That's an interesting point, in the sense of
- (champion@uk.ac.cov.cck) | being very not interesting at all. - The Liar
-