National Instruments

  www.ni.com
  www.ni.com

Interview Question

R&D Software Engineer Interview(Student Candidate) Austin, TX

Given a linked list, write a function that will print the

  list in reverse.
Tags:
technical, c++
Answer

Interview Answer

2 Answers

0

Do this in linear O(n) time without recursion and without creating a copy of the list.

[Hint] You can modify the list, as long as you put it back the way it started.

Interview Candidate on Apr 7, 2011
0

Traverse the list from start to end updating the link addresses such that the second node points to first, third node points to second and so on. when we reach the last node we will have reverse list. Now repeat the whole process but this time printing the elements of the nodes. We will get the original list back and items printed are in reverse order as well.
I am proud of myself !! :)

Mrig on Jan 8, 2013

Add Answers or Comments

To comment on this Question, Sign In with Facebook or Sign Up