home *** CD-ROM | disk | FTP | other *** search
- Organization: Applications Software, Carnegie Mellon, Pittsburgh, PA
- 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+
- Newsgroups: comp.lang.c
- Message-ID: <geyke2W00VQsEhTcIK@andrew.cmu.edu>
- Date: Fri, 6 Nov 1992 19:14:58 -0500
- From: Richard Dale Romero <rickr+@CMU.EDU>
- Subject: Re: To Recurse or NOT to recurse?
- In-Reply-To: <1992Nov6.185136.8055@netcom.com>
- References: <1992Nov6.185136.8055@netcom.com>
- Lines: 17
-
- Excerpts from netnews.comp.lang.c: 6-Nov-92 To Recurse or NOT to
- recurse? Stephen Schow@netcom.com (577)
-
- > What is better to do when traversing a linked list..... SHould I use
- > recursion to search down through the list for the last node, or should I
- use a while loop? What or the pro's and con's of each?
-
- Some compilers are really smart, and they will turn your code into (if
- it is tail recursion) into a while loop. Others won't. If it doesn't,
- are you wasting space? Yes. How much? Well, you're using O(N) space
- when it can be done in O(1) space. That's a lot as far as I'm
- concerned. And speed? Bit trickier, and dependent on the machine you
- use, but I'd lay odds on the while loop, say 10:1, that it'd be faster.
-
- -rick
-
-
-