home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16612 < prev    next >
Encoding:
Text File  |  1992-11-16  |  1.3 KB  |  49 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!gumby!wupost!csus.edu!netcom.com!sjs
  3. From: sjs@netcom.com (Stephen Schow)
  4. Subject: Re: Printing out trees
  5. Message-ID: <1992Nov16.195947.25441@netcom.com>
  6. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  7. References: <1992Nov16.081021.9316@netcom.com>
  8. Date: Mon, 16 Nov 1992 19:59:47 GMT
  9. Lines: 38
  10.  
  11. I used the following code to display the structure of a binary tree for
  12. a CS class in college.  It works great, but I wish I had a way to show
  13. the lines that connect the nodes (with characters that is).  Any suggestions?
  14.  
  15. Here's my code...
  16.  
  17. InGraph(tree,level)
  18. struct node *tree;
  19. int level;
  20. {
  21.      if (tree != NULL)
  22.           {
  23.           InGraph(tree->left,level+1);
  24.           PrintLevel(tree,level);
  25.           InGraph(tree->right,level+1);
  26.           }
  27. }
  28.  
  29.  
  30. PrintLevel(tree,level)
  31. struct node *tree;
  32. int level;
  33. {
  34.      int i;
  35.  
  36.  
  37.      for(i=1;i<=level*8;i++)
  38.           fprintf(stdout," ");
  39.      fprintf(stdout,"(%d)%s\n",level,tree->info);
  40. }
  41.  
  42. -- 
  43. ------------------------------------------------------------------
  44. Steve Schow    | But you don't have to use the claw, if you
  45. sjs@netcom.com | pick the pear with the big paw paw......
  46.                | Have I given you a clue......?
  47.                |                       - Baloo the Bear
  48. ------------------------------------------------------------------
  49.