GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javascript.info — Output a single-linked list back to the lesson Output a single-linked listimportance: 5 Let’s say we have a single-linked list (as described in the chapter Recursion and stack):
Write a function Make two variants of the solution: using a loop and using recursion. What’s better: with recursion or without it? Loop-based solutionThe loop-based variant of the solution: Please note that we use a temporary variable
…But that would be unwise. In the future we may need to extend a function, do something else with the list. If we change Talking about good variable names, From the other side, the role of Recursive solutionThe recursive variant of Now what’s better? Technically, the loop is more effective. These two variants do the same, but the loop does not spend resources for nested function calls. From the other side, the recursive variant is shorter and sometimes easier to understand. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |