1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Trying to implement my own iterator in Java

  1. Oct 14, 2011 #1
    1. The problem statement, all variables and given/known data
    Basically, I am assigned to implement my own iterator using a Doubly Linked List. The methods, of course, are hasNext(), next(), and remove(). The one that is giving me the most grief is the remove() method.


    2. Relevant equations



    3. The attempt at a solution

    The code that I have currently is:

    Code (Text):

    public void remove() {
        lastItemReturned = lastItemReturned.prev;
        nextItem = lastItemReturned.next.next;
        index--;
    }
     
    Now, this could actually be right and I may be messing up somewhere else in the code, but I have a feeling this is not the case. Does anybody know if this part of code is right?
    1. The problem statement, all variables and given/known data



    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: Trying to implement my own iterator in Java
  1. Java Scanner issues (Replies: 0)

  2. Java maze building (Replies: 0)

Loading...