finding element within singly linked list
Posted on 2013-07-01
I am working on a question and need some help getting this going.
Write a function that would return the 5th element from the end in a singly linked list of integers, in one pass, and then provide a set of test cases against that function. Assume the list size cannot be known without traversing the list.
I will need a class for the code...and then not sure about the test cases....unless unit tests would be the same thing..if so then another class.
I know I want the 5th element from end.
I do not know the end.
I start a count of some sort that looks ahead in the list until it finds the end...and somehow the other count is looking back to the 5th element...not sure how that works ...but sord of can picture this.
Then I am not sure what all you would test...I guess maybe you would test that there is an a value in the list, that the value is hte 5th element, perhaps that there are even 5 elements...not sure what else to test for here.....