Print linked list backwards



In an interview for an embedded software position recently I was asked
to write code, in C, for printing the contents of a linked list
backwards. After a few minutes I came up with the recursive solution.
Being that recursion is frowned upon in embedded software, the answer
was not what the interviewer expected, but alas it was correct. I asked
some friends how they would have answered and another answer is to
reverse the list and then print the contents as you reverse the list a
second time.

I was searching for any other possible solutions and it seems these 2
are the most common solutions. However, someone mentioned that if there
is a constraint that the list is unmodifiable, there is another
solution but didn't provide that solution. Can anyone provide a
solution besides the 2 I mentioned, especially one that would work
without modifying the list?

Thanks,

Josh

.



Relevant Pages

  • Re: Print linked list backwards
    ... backwards. ... After a few minutes I came up with the recursive solution. ... Being that recursion is frowned upon in embedded software, ... reverse the list and then print the contents as you reverse the list a ...
    (comp.lang.c)
  • Re: Reverse words in a string (Another Interview question)
    ... > linked list and then try to reverse the linked list. ... When I do interview questions, I let them solve it any way they can. ... He was relying on his on particular implementation ... Second was an assembly language job where the guy asked me to describe ...
    (comp.programming)
  • Re: How many bytes per Italian character?
    ... never bother to memorize all arguments of CreateFile, ... allocate memory?" ... But someone at MS told me that her standard interview question is "here is ... The question was how to reverse a string using only 1 free character. ...
    (microsoft.public.vc.mfc)
  • Re: How many bytes per Italian character?
    ... I tend to despise these kinds of questions in an interview. ... insight or they are insultingly trivial or they require obscure knowledge. ... and the interviewer said "what's the fastest way to allocate ... The question was how to reverse a string using only 1 free character. ...
    (microsoft.public.vc.mfc)