home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!gumby!wupost!csus.edu!netcom.com!sjs
- From: sjs@netcom.com (Stephen Schow)
- Subject: Re: Printing out trees
- Message-ID: <1992Nov16.195947.25441@netcom.com>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <1992Nov16.081021.9316@netcom.com>
- Date: Mon, 16 Nov 1992 19:59:47 GMT
- Lines: 38
-
- I used the following code to display the structure of a binary tree for
- a CS class in college. It works great, but I wish I had a way to show
- the lines that connect the nodes (with characters that is). Any suggestions?
-
- Here's my code...
-
- InGraph(tree,level)
- struct node *tree;
- int level;
- {
- if (tree != NULL)
- {
- InGraph(tree->left,level+1);
- PrintLevel(tree,level);
- InGraph(tree->right,level+1);
- }
- }
-
-
- PrintLevel(tree,level)
- struct node *tree;
- int level;
- {
- int i;
-
-
- for(i=1;i<=level*8;i++)
- fprintf(stdout," ");
- fprintf(stdout,"(%d)%s\n",level,tree->info);
- }
-
- --
- ------------------------------------------------------------------
- Steve Schow | But you don't have to use the claw, if you
- sjs@netcom.com | pick the pear with the big paw paw......
- | Have I given you a clue......?
- | - Baloo the Bear
- ------------------------------------------------------------------
-