Tags


Consider the linked list

34 – 45 – 9 – 3 – 23 – 04

To find the 3rd last element from last:

Start pushing each element into stack.  So stack will contain:

Top of stack :-

04

23

3

9

45

34

End of stack

Now keep on popping the element from stack till the desired element is retrieved.

Advertisements