News for hackers. Stuff that matters.
Re:Nth-to-Last Element in a Singly Linked List by liamk on Sunday January 31, 2010 @11:05PM (#1091752)
What about going through the list once, put each node onto a stack, then pop n - 1 elements off the stack, and the nth last element will be on the top of the stack. Edit: uses too many pointers as cperciva points out below.
Re:Nth-to-Last Element in a Singly Linked List by cperciva on Sunday January 31, 2010 @11:17PM (#1091765)
That uses N additional memory locations, not 3.