home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16116 < prev    next >
Encoding:
Text File  |  1992-11-08  |  1.3 KB  |  29 lines

  1. Organization: Applications Software, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!decwrl!netsys!agate!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!rr2p+
  3. Newsgroups: comp.lang.c
  4. Message-ID: <geyke2W00VQsEhTcIK@andrew.cmu.edu>
  5. Date: Fri,  6 Nov 1992 19:14:58 -0500 
  6. From: Richard Dale Romero <rickr+@CMU.EDU>
  7. Subject: Re: To Recurse or NOT to recurse?
  8. In-Reply-To: <1992Nov6.185136.8055@netcom.com>
  9. References: <1992Nov6.185136.8055@netcom.com>
  10. Lines: 17
  11.  
  12. Excerpts from netnews.comp.lang.c: 6-Nov-92 To Recurse or NOT to
  13. recurse? Stephen Schow@netcom.com (577)
  14.  
  15. > What is better to do when traversing a linked list..... SHould I use
  16. > recursion to search down through the list for the last node, or should I
  17. use a while loop?  What or the pro's and con's of each?
  18.  
  19. Some compilers are really smart, and they will turn your code into (if
  20. it is tail recursion) into a while loop.  Others won't.  If it doesn't,
  21. are you wasting space?  Yes.  How much?  Well, you're using O(N) space
  22. when it can be done in O(1) space.  That's a lot as far as I'm
  23. concerned.  And speed?  Bit trickier, and dependent on the machine you
  24. use, but I'd lay odds on the while loop, say 10:1, that it'd be faster.
  25.  
  26. -rick
  27.  
  28.  
  29.