Created
December 11, 2012 05:57
-
-
Save gaohao/4256219 to your computer and use it in GitHub Desktop.
Delete the nth last element from a singly linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Have two pointers ptr1 and ptr2 pointing to head of linked list | |
2. Traverse one pointer say ptr2 to distance n from head | |
3. Now, traverse both | |
4. When ptr2 reaches the tail, ptr1 is at distance "n" from the tail of linked list | |
recursive? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment