home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16260 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  1.0 KB

  1. Path: sparky!uunet!ontek!mikey
  2. From: mikey@ontek.com (euphausia superba)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: To Recurse or NOT to recurse?
  5. Message-ID: <2183@ontek.com>
  6. Date: 9 Nov 92 18:26:19 GMT
  7. References: <1992Nov6.185136.8055@netcom.com>
  8. Organization: Ontek Corporation -- Laguna Hills, California
  9. Lines: 15
  10.  
  11. In comp.lang.c, sjs@netcom.com (Stephen Schow) writes:
  12. | What is better to do when traversing a linked list..... SHould I use recursion
  13. | to search down through the list for the last node, or should I use a while
  14. | loop?  What or the pro's and con's of each?
  15.  
  16. I've seen several replies so far to the above which answer a more
  17. general question than Mr. Schow asked.  The "best" solution in terms of
  18. minimizing execution speed and stack space is to maintain a pointer to
  19. the last item on the list; then no search is necessary.  The only
  20. additional costs are that the (probably only one) function that adds
  21. things to the list needs to update the pointer (which is a trivial
  22. operation at that point) and the extra pointer.
  23.  
  24.        the krill
  25.  
  26.