aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 8707
    
    6

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
Consider Paul's rocket mass heater.
 
subject: get fifth element from last linked list
 
Similar Threads
need to implement stored moves in linked lists
Creating Linked List
Changing removeAt method to swap instead of removing
get fifth element from last for a Singly linked list
Ordered Doubly Linked List