Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Java in General and the fly likes get fifth element from last linked list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

get fifth element from last linked list

Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
Hi,
Could anyone help me with a method for a Singly Linked List which gets fifth element from last linked list

I have the logic here:

1) have two ptrs. F_Ptr & S_Ptr.
2) Let the ptrs point to the START.
3) Take n as the offset.
4) Start traversing the S_Ptr after the F_Ptr after n.

suppose you want to find 5 element from the last of the list.

In the above case.

1) n = 5 // 5th element from the last
2) check atleast this many elements are there in the list before beginging


Thanks,
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 9070
    
    9

Please do not post the same question more than once. It causes confusion and duplication of effort as the community tries to help everyone.


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get fifth element from last linked list