home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ontek!mikey
- From: mikey@ontek.com (euphausia superba)
- Newsgroups: comp.lang.c
- Subject: Re: To Recurse or NOT to recurse?
- Message-ID: <2183@ontek.com>
- Date: 9 Nov 92 18:26:19 GMT
- References: <1992Nov6.185136.8055@netcom.com>
- Organization: Ontek Corporation -- Laguna Hills, California
- Lines: 15
-
- In comp.lang.c, sjs@netcom.com (Stephen Schow) writes:
- | 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?
-
- I've seen several replies so far to the above which answer a more
- general question than Mr. Schow asked. The "best" solution in terms of
- minimizing execution speed and stack space is to maintain a pointer to
- the last item on the list; then no search is necessary. The only
- additional costs are that the (probably only one) function that adds
- things to the list needs to update the pointer (which is a trivial
- operation at that point) and the extra pointer.
-
- the krill
-
-