Aj Prieto wrote:If I have a list that contains (1, 2, 3) and I start the iterator at index 3, this is what my code outputsThe values in the [] were inputted by me as to what is expected. Is my thinking correct or are my expected values wrong?
Well, there's more than one way to do it, and it would actually be better if you showed us ALL the code for the class, especially the fields you're using.
It's also a bit difficult to understand your output, but I would remind you that Java List and array indexes are 0-BASED.
However, the general idea is this:
If you're starting with an index that is outside the bounds (as 3 is for an array of size 3), then just treat it as 'exclusive' (ie, each call to hasPrevious()/previous() checks or returns the element before the 'current' index.
So, assuming you have a 'currentIndex' field, hasPrevious() might look something like:
return currentIndex > 0 && currentIndex <= list.size();
remove() is a bit trickier, but it's usually supposed to remove the current element, so you generally don't need to update any indexes. The same with set() I believe: it simply inserts a value at the current index.
The real tricky part comes in combininghasPrevious()/previous() and hasNext()/next(), but it doesn't appear that you need to worry about that yet.
HIH
Winston
Isn't it funny how there's always time and money enough to do it WRONG?
I've updated the first post to include the entire class. The methods marked with //TODO are the ones we have to do and the others were provided. A Double Linked Node list is used for the tests.
Aj Prieto wrote:A Double Linked Node list is used for the tests.
Ah. Well, in that case, implementation will be a bit different.
Winston
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
4
posted
2
Please do not remove code from, or alter, old posts. That makes the remainder of the thread incomprehensible.
If you think somebody has plagiarised your code, your college will find that because there is software which trawls the internet looking for similar code. I am sure it will find the code in your post.
I think little will be gained from further discussion, and am closing this discussion.