|
|
|
|
|
by davelnewton
4270 days ago
|
|
I think you've missed my point. Your "sound judgement" argument is orthogonal to my "being able to reason about fundamental data structures". I doubt most people will need to manually re-write list operations. Most people will need to reason about fundamental data structures. Ultimately I guess I just find it impossible to believe that basic coding skills are no longer relevant to a large number of commenters here, and that using a "but I can find it on teh Googs" is a reasonable response to "please write a few lines of trivial code that operate on a trivial, but fundamental, data structure". |
|
~ Single or doubly linked?
~ How is the data structure implemented (e.g. is there a header structure and to what does it point)?
~ What does "reverse" mean? mutate in place? create a new list? and if I am to mutate it in place, why?
~ Reversing a linked list is O(n). One implementation us pretty much as good as another. It doesn't really differentiate on insight into the problem.
~ Winding up in a situation where reversing a list is critical smells like bad design...a stack/queue would have been a better choice upstream than a queue/stack.
But though all that may make for interesting conversation, "with a library call" is the only professional answer to "How would you write a function to reverse a list?"